【发布时间】:2013-01-31 22:05:14
【问题描述】:
我正在开发一个 ASP.NET MVC 4 应用程序,并尝试在 Entity Framework 5 中运行这个 Lambda 表达式。
var customer = db.GNL_Customer.Where(d => d.GNL_City.FKProvinceID == advancedProvinceID || advancedProvinceID == null)
.Where(d => d.FKCityID == advancedCityID || advancedCityID == null)
.Where(d => d.FKDepartmentStoreID == advancedDepartmentStoreID || advancedDepartmentStoreID == null)
.Where(d => d.GNL_CustomerLaptopProduct.Where(r => String.Compare(r.BrandName, brandID) == 0 || brandID == null));
我收到此错误:
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<ITKaranDomain.GNL_CustomerLaptopProduct>' to 'bool'
我知道最后一个 where 子句是错误的,但我不知道如何更正它。
【问题讨论】:
-
正如 Andrew 在他的回答中指出的那样,您需要使用
Any作为Where will return anIEnumerable` 并且 Any的谓词需要一个bool返回函数。
标签: c# entity-framework