Strange WHERE predicate begin generated when check for NULL
See original GitHub issueHello.
I have met strange SQL generated when adding null-check in WHERE clause:
var veh = con.Vehicles.FirstOrDefault(x => x.StyleId != null && x.StyleId != -1000);
I get this SQL:
-- SqlServer.2008
SELECT TOP (1)
[x].[VehicleId],
[x].[LV_autoStyleId]
FROM
[Vehicle] [x]
WHERE
[x].[LV_autoStyleId] IS NOT NULL AND ([x].[LV_autoStyleId] IS NULL OR [x].[LV_autoStyleId] <> -1000)
LV_autoStyleId
is checked against NULL and NOT NULL simultaneously. Is it by design or I am doing something wrong?
This doesn’t bother me much, just curious if it is normal.
I saw it in 2.6.4 and still see this in 2.7.4 (had to update just to check this is bug and was fixed).
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
CoreData fetchRequest with predicate incorrectly skips ...
I fail to see why this could happen, because if I don't specify a predicate all objects get fetched properly. Objects with NULL...
Read more >Weird nullreference exception. When using predicates
The simple solution is to test the variable before you try to use it. C#. if (_Dealer != null) { ...
Read more >sql server - Avoiding null comparisons in where clause
DpdRoute WHERE DestinationCountry = @COUNTRY) SELECT * FROM Country WHERE BeginPostCode IS NULL AND ENDPOSTCODE IS NULL UNION ALL SELECT ...
Read more >SQL: Empty value list for the IN predicate (literals, not ...
To work around this issue I just return an empty collection in a DAO object, not letting the syntactially illegal SQL code to...
Read more >Strange Behaviour in Null field = Not Null field evaluation
The datetime field is set on the zxt_dnn_sitelog_src view but it is null in the zxt_dnn_sitelog_m1 view. This statement evaluates to 'notequal'. Copy....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@jods4, try to set this global configuration setting. I hope it works, we have plans to review this in near future https://github.com/linq2db/linq2db/blob/master/Source/LinqToDB/Common/Configuration.cs#L148
@sdanyliv Great, thanks!