动态LINQ2Entities查询无法将IEnumerable转换为布尔

本文关键字:IEnumerable 转换 布尔 LINQ2Entities 查询 动态 | 更新日期: 2023-09-27 18:27:22

这里的建立和组织行给出了一个错误,即它们无法将IEnumerable隐式转换为bool。我错过了什么?在方法结束之前,我不能使用贪婪运算符。我确信这很简单,但我看不见。

IQueryable<User> query = context.Users;
if (usvm.EstablishmentId > 0)
    query = query.Where(x => x.UserEstablishments
        .Where(y => y.UserEstablishmentId == usvm.EstablishmentId));
if (usvm.OrganisationId > 0)
    query = query.Where(x => x.UserEstablishments
        .Where(y => y.Establishment.OrganisationId == usvm.OrganisationId));
if (!String.IsNullOrEmpty(usvm.Forename))
    query = query.Where(x => x.Forename == usvm.Forename);
if (!String.IsNullOrEmpty(usvm.Surname))
    query = query.Where(x => x.Surname == usvm.Surname);
if (usvm.DOB != null)
    query = query.Where(x => x.DOB == usvm.DOB);
List<User> m = query.ToList();
return ToViewModel(m);

动态LINQ2Entities查询无法将IEnumerable转换为布尔

您可以使用任何方法:

if (usvm.EstablishmentId > 0)
    query = query.Where(x => x.UserEstablishments
        .Any(y => y.UserEstablishmentId == usvm.EstablishmentId));
if (usvm.OrganisationId > 0)
    query = query.Where(x => x.UserEstablishments
        .Any(y => y.Establishment.OrganisationId == usvm.OrganisationId));
相关文章: