c# - Why does using .Date with EF work sometimes, but not others? -


vs 2013, ef6 code first

i'm using code , works fine:

var timeslots = vehicle.vehicletimeslots.where(t =>     t.createdate.date <= currentdate.date     && (t.deletedate == null || t.deletedate.value.date > currentdate.date)     && t.dayofweek == dayofweek).orderby(t => t.starttime); 

however, if try runtime error "the specified type member 'date' not supported in linq entities. initializers, entity members, , entity navigation properties supported." (db instance of dbcontext):

var previousreservation = db.reservationtimeslots.singleordefault(t =>     t.reservationdate.date == reservationtimeslot.reservationdate.date     && t.vehicletimeslotid == reservationtimeslot.vehicletimeslotid); 

there's many other questions issue , know can use dbfunctions.truncatetime() in latter bit of code (which doing). guess difference first bit of code operating against vehicle entity object while second bit of code operating directly against dbcontext. aren't both linq entities though?

you answered own question. right, first query operating against in-memory object (vehicle) , can use property/feature.

whereas second linq expression translated underlying data source language (probably sql) , each expression doesn't have equivalent translation available in entity framework.

aren't both linq entities though?

no, first 1 linq objects , second expression in linq entities.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -