我開發一個ASP.NET MVC 4應用程序,我想在實體框架5無法隱式轉換類型System.Collections.Generic.IEnumerable <>爲bool
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));
運行這個Lambda表達式
我得到這個錯誤:
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<ITKaranDomain.GNL_CustomerLaptopProduct>' to 'bool'
我知道,最後的where子句是錯誤的,但我不知道如何糾正它。
正如Andrew在他的回答中指出的那樣,您需要使用'Any'作爲'Where where will return an'IEnumerable''而Any'的謂詞需要一個'bool'返回函數ñ。 –