我有下面的方法存在問題:爲什麼這個LINQ to EF查詢不起作用?
public IQueryable<Customer> ListCustomers(int? parentId)
{
Debug.Assert(parentId == null);
//var list = _customerRepository.List().Where(c => c.ParentId == null);
var list = _customerRepository.List().Where(c => c.ParentId == parentId);
return list;
}
我有我的數據庫爲NULL的ParentId一個客戶。當我使用ListCustomers(null)
調用方法時,list
對於return語句是空的。如果我使用硬編碼的空值交換註釋掉的行並查詢,則列表包含我的一個客戶。
什麼會導致這兩個查詢之間的差異?爲什麼c.ParentId == parentId
沒有返回任何東西?
當'parentId'有一個值時,我用這個解決方案得到一個EF'NotSupportedException'。其他人能證實這一點嗎? –