我使用Linq到EF並嘗試從ObjectSet獲取FirstOrDefault entitiy。 查詢看起來是這樣的:null Linq查詢
Notification not = new Notification();
........
//not.SubTypeID = null;
var elem = ent.Notifications.FirstOrDefault(p =>
p.ID == not.ID &&
p.SubTypeID == not.SubTypeID &&
p.Location == not.Location &&
p.TypeID == ns.TypeID
);
有時SubTypeID
可以null
在這種情況下沒有什麼elem
是returnced althogh p.SubTypeID
和not.SubTypeID
都是null
。
但奇怪的是,當我運行此查詢:
var elem = ent.Notifications.FirstOrDefault(p =>
p.ID == not.ID &&
p.SubTypeID == null &&
p.Location == not.Location &&
p.TypeID == ns.TypeID
);
一切正常,我在elem
看到的數據。
所以我做錯了什麼,當這兩個查詢有什麼不同時not.SubTypeID
是null
。
可能重複的[我如何查詢空值在實體框架?](http://stackoverflow.com/questions/682429/how-can-i-query-for-null-values-in-entity-框架) –