EF排序问题

时间:2012-08-02 11:42:30

标签: c# linq entity-framework lambda linq-to-entities

linq表达式有问题。 我想从db获取datetime命令的一些数据。早期有字符串字段排序。 排序表达式(按字符串):

Expression<Func<Matter, Object>> result = e => e.MatterNumber;
//In debug mode: {e => e.MatterNumber}

工作正常

排序表达式(按datetime或int):

Expression<Func<Matter, Object>> result = e => e.Created;
//In debug mode: {{e => Convert(e.Created)}}

这会引发错误: {“无法将类型'System.Int32'强制转换为'System.Object'.LINQ to Entities仅支持转换实体数据模型基元类型。”} < / p>

请帮助:)

1 个答案:

答案 0 :(得分:1)

alexei,你可能想看看这个SO问题:

Entity Framework: LINQ to Entities only supports casting Entity Data Model primitive types

或者这个:

Help me understand "LINQ to Entities only supports casting Entity Data Model primitive types"

最后在SO:

Entityframework 4.0 .CreateQuery<T> and OrderBy exception

并在forums.asp.net上:

http://forums.asp.net/t/1580414.aspx/1

所有4个问题都以稍微不同的方式处理这个问题,但希望在您的方案中有所帮助。

相关问题