i’m intend to use both Linq to sql and EF 4.x, in same project (for some reason),
but there are some stuff in EF, that IMO is “Weird” like this:
db.SomeTable.Where(x => x.Date > DateTime.Now.Date);
which must be written in this way
db.SomeTable.Where(x => EntityFunctions.TruncateTime(x) > EntityFunctions.TruncateTime(DateTime.Now.Date));
Is there any way, I can add functionalities to EF, or change this behavior, because LinqToSql don’t have these weird syntax
Actually it is possible to intercept the query and rewrite it. See the
IQueryable.ProviderandIQueryable.Expressionproperties. But this involves writing a customExpressionVisitorto translate the call and gets complicated a very quickly.If this code above is the only mismatch between Linq-To-SQL and EF you encountered, you could rewrite the query like this:
I’m pretty sure that EF should support this comparison and so should Linq-To-Sql.
If you want to try the first solution, I recommend you create a
IQueryable<T>-wrapper for theObjectSet<T>returned by the EF and set a breakpoint when performing simple queries and see how the expression tree is actually stored within the query, this might give an impression of what to look for and what to replace it with.