Coalesce with not equal unexpected SQL translation #16955
Labels
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-bug
Milestone
Evaluation of simple LINQ expression involving null coalescing operator and subsequent primitive not-equals comparison within predicate returns an unexpected result set.
Given data saved:
the LINQ
evaluates to the result
[ "HasTestId", "NullTestId" ]
instead of the expected[ "HasTestId" ]
. This is because the above LINQ is compiled by EF Core to the SQL:The extraneous
OR "o"."TestId" IS NULL
added to theWHERE
clause seems incorrect IMHO. Interestingly, by switching the predicate from!=
to==
the LINQ evaluates to the expected result[ "ZeroTestId", "NullTestId" ]
.Steps to reproduce
Clone repro project at ickers/ef-core-coalesce-not-equal-query@6d5af16 (multi-targeted project for
netcoreapp2.0/ef-core-2.0.3
,netcoreapp2.1/ef-core-2.1.11
,netcoreapp2.2/ef-core-2.2.6
- issue is reproducible in all three runtime/EF Core versions).Further technical details
EF Core version:
2.2.6
,2.1.11
,2.0.3
Database Provider:
Microsoft.EntityFrameworkCore.Sqlite
(originally observed withMicrosoft.EntityFrameworkCore.SqlServer
)Operating system: Linux Mint 18
IDE: VS Code 1.36 (originally observed with Visual Studio 2017 15.4)
The text was updated successfully, but these errors were encountered: