Cannot implicitly convert type System.Collections.Generic.IEnumerable<> to bool

前端 未结 2 1232
长情又很酷
长情又很酷 2020-12-18 05:05

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 =>         


        
相关标签:
2条回答
  • 2020-12-18 05:21

    Use Where ( Any ) in last statement to select customers which have at least one product satisfying your conditions:

    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 => brandID == null || d.GNL_CustomerLaptopProduct.Any(r => r.BrandName == brandID));
    
    0 讨论(0)
  • 2020-12-18 05:35

    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));
    
    0 讨论(0)
提交回复
热议问题