无法隐式转换类型System.Collections.Generic.IEnumerable<布尔 [英] Cannot implicitly convert type System.Collections.Generic.IEnumerable<> to bool
本文介绍了无法隐式转换类型System.Collections.Generic.IEnumerable<布尔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发ASP.NET MVC 4应用程序,并且试图在Entity Framework 5中运行此Lambda表达式。
I'm developing an ASP.NET MVC 4 Application and I'm trying to run this Lambda expression in Entity Framework 5.
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));
我收到此错误:
不能将类型'System.Collections.Generic.IEnumerable< ITKaranDomain.GNL_CustomerLaptopProduct>'隐式转换为'bool'
I知道最后一个where子句是错误的,但是我不知道如何纠正它。
I know that the last where clause is wrong but I don't know how to correct it.
推荐答案
您可能想要另一个 .Any
而不是。在您的
结束: .Any
子句中的
You might want another .Any
instead of a .Where
in your .Any
clause at the end:
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)
.Any(d => d.GNL_CustomerLaptopProduct.Any(r => String.Compare(r.BrandName, brandID) == 0 || brandID == null));
这篇关于无法隐式转换类型System.Collections.Generic.IEnumerable<布尔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文