c# - LINQ to Entities does not recognize the method 'Int64 Max(Int64, Int64)' method, and this method cannot be translated into a store expression -


i'm getting error message during runtime

linq entities not recognize method 'int64 max(int64, int64)' method, , method cannot translated store expression.

when try this:

return _dbcontext.appointment.where(x => math.max(x.appointment.starttime.ticks, starttime.ticks) <= math.min(x.appointment.endtime.ticks, endtime.ticks)); 

the idea behind query "if latest start time before earliest end time, have overlap/touching" in date , time.

is there way line working? checked if entityfunctions has 'something', wasn't case.

you must keep in mind every iqueryable provider implemented in own way. query work in linq objects (as not gets translated anything) may or may not work in iqueryable providers.

in specific case, it's telling has no idea on how translate math.max , math.min sql commands. , that's correct, since ef doesn't recognize methods.

in opinion easiest way accomplish need reading max , min value 2 different queries , logic in plain c#. this:

var min = mycontext.mydbset.min(c => c.field); var max = mycontext.mydbset.max(c => c.field); if (max <= min) {     // } 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -