linq exception : This function can only be invoked from LINQ to Entities

前端 未结 1 1972
一个人的身影
一个人的身影 2021-01-12 23:45

I\'m trying to get data which is kept on cache. But it throws an exception on \"select new FilterSsrsLog\" line. Exception: This function can only be invoked from LINQ to En

1条回答
  •  生来不讨喜
    2021-01-13 00:24

    The reason you are getting this error is that the query is executed in memory, not in RDBMS. The DiffMilliseconds function is a marker that Entity Framework provider converts to RDBMS-specific SQL to send to your RDBMS. The function does not compute its result when applied to an IQueryable in memory, throwing an exception instead.

    If you want to run this query in memory, replace

    TotalTime = EntityFunctions.DiffMilliseconds(r.TimeStart, r.TimeEnd)
    

    with

    TotalTime = (r.TimeEnd - r.TimeStart).TotalMilliseconds
    

    Subtraction of two dates produces a TimeSpan value from which you can take its TotalMilliseconds property.

    0 讨论(0)
提交回复
热议问题