Closed
Description
Issue/Scenario
We are having troubles with some of our queries that contain null checks and don't return any data when the null check is in place. Our setup is as follows:
- database first (legacy database)
- one-to-zero-or-one relationship between two tables
- some queries contain null checks on the zero-or-one side and do not return data because of the null check
We are not sure if this is
- expected behavior/by design (zero-to-one-side mapped with Id generated by foreign)
- wrong mapping on our side
- a bug
Steps to reproduce
- Query data:
.Query<Sheep>().Where(s => s.Name == "Dolly")
- **Result: *** Sheep "Dolly" returned
- Add a null check to the query (zero-or-one-side):
.Query<Sheep>().Where(s => s.Name == "Dolly" && s.SlaughterInfo == null)
- **Result: *** no data returned due to generated SQL statement containing
(slaughterInfo.SheepId is null)
I have created a sample project that demonstrates the issue.
Even if this is the expected behavior: from a developer's perspective who writes the Linq query it is not obvious that this null check is causing the query to fail without looking at the underlying mapping (or writing a test :-)).
Notes
We are using the following Versions:
- NHibernate 5.3.5
- FluentNhibernate 3.1.0
Workarounds
- check all queries in code and remove null checks if possible