question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Strange WHERE predicate begin generated when check for NULL

See original GitHub issue

Hello.

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:open
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
sdanylivcommented, Sep 5, 2019

@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

0reactions
jods4commented, Sep 5, 2019

@sdanyliv Great, thanks!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found