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
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<T>
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.