使用Entity Framework 4.0的Lambda表达式错误

时间:2015-09-01 05:38:01

标签: linq entity-framework-4

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

  

无法隐式转换类型&system; system.collections.generic.Ienumerable'到了布尔'

代码:

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();

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

1 个答案:

答案 0 :(得分:0)

你的where条件应该返回布尔值,但是它会返回带有下面代码的整数枚举。

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

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

等条件