Entity Framework object limitations in aggregate LINQ query

前端 未结 1 1520
野性不改
野性不改 2021-01-21 23:33

I have a rather complicated query that I\'d like to have return some particular types. Mostly concerning date / time calculations or string values, the Entity Framework seems t

相关标签:
1条回答
  • 2021-01-22 00:21

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

    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
            };
    
    0 讨论(0)
提交回复
热议问题