【发布时间】:2017-02-05 17:50:44
【问题描述】:
我的 Linq 查询(我想获取按订单数量排序的项目列表)
var x = context.Items.Include("Item_qualities").Join(
context.Orders,
i => i.Id,
o => o.Item_id,
(i, o) => new { i, o }
)
.GroupBy(e => new { e.i })
.Select(w => new { w.Key.i, c = w.Count() })
.OrderByDescending(y => y.c)
.ToList().Select(u=>u.i);
最后一部分Select(u=>u.i) 抛出异常
text、ntext 和 image 数据类型无法比较或排序, 除非使用 IS NULL 或 LIKE 运算符。
【问题讨论】:
-
查看异常的文本。它想告诉你什么?
-
匿名类型必须有变量名:{ w.Key.i, c = w.Count() }
-
@CoryNelson:异常文本说这些类型无法比较。但我的 u.i 不是 text、ntext 或 image 数据类型。
-
context是实体框架上下文吗?
标签: c# entity-framework linq linq-to-entities