简体   繁体   中英

Entity Framework converting the query to is null

When I run = null in Management Studio, it returns no rows but when I run is null I get data back. In Entity Framework, it is converting the query to is null, Is there any alternative so I can just do the = null in Entity Framework?

This return no rows

SELECT *
FROM cart c
WHERE OrderId = NULL

This return 1000 rows

SELECT *
FROM cart c
WHERE OrderId IS NULL

EF List count 1000 rows

var Pending = (from c in db.Cart 
               where sc.OrderId == null
               select sc.CartId).ToList();

Null means unknown value. In SQL trying to equate any value to NULL will result in FALSE, which makes sense. As such, 2 = NULL is FALSE. NULL = NULL is FALSE. However, column IS NULL checks that the value of the column is NULL.

The semantics of C# is different and eventually translates your query to IS NULL when the EF framework sends the query to the server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM