且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

合计LINQ查询实体框架对象限制

更新时间:2022-02-19 23:12:11

您只能使用支持成员L2E查询,的 日期是不是那些之一。

You can only use supported members in L2E queries, and Date isn't one of those.

一个解决方法是打破你的单L2E查询到一个L2E查询后跟一个LINQ到对象查询:

One workaround is to break your single L2E query into one L2E query followed by one LINQ to Objects query:

var q = from e in Context.Entities
        select new
        {
            Id = e.Id,
            DateTime = e.DateTime
        };

var r = from e in q.AsEnumerable()
        select new
        {
            Id = e.Id,
            Date = e.DateTime.Date
        };