【问题标题】:Lambda expression error using Entity Framework 4.0使用 Entity Framework 4.0 的 Lambda 表达式错误
【发布时间】:2015-09-01 13:49:21
【问题描述】:

我正在使用某些条件进行过滤。我使用以下条件来检查值。但我得到这个错误:

无法将类型“system.collections.generic.Ienumerable”隐式转换为“bool”

代码:

var topLocationIds = Model.Where(q => q.JobLocations.Select(c=>c.Locationid))
                                   .GroupBy(c=>c.JobLocations.Select(c=>c.LocationId)))
                                   .OrderByDescending(gp => gp.Count())
                                   .Take(5)
                                   .Select(g => g.Key).ToList();

为什么会出现这个错误?我只能明智地采用外键表值..

【问题讨论】:

  • 你想用这个条件检查什么? Where(q => q.JobLocations.Select(c=>c.Locationid))

标签: linq entity-framework-4


【解决方案1】:

您的 where 条件应返回布尔值,但它会使用以下代码返回整数枚举。

Model.Where(q => q.JobLocations.Select(c=>c.Locationid))

Select 用于投影数据。在where 中,您应该检查q.someid>1 之类的条件

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-31
    • 2020-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多