I\'m using System.Data.Objects.EntityFunctions.TruncateTime method to get date part of a datetime in my query:
if (searchOptions.Date.HasValue)
You can define a new static function (you can have it as an extension method if you want):
[EdmFunction("Edm", "TruncateTime")]
public static DateTime? TruncateTime(DateTime? date)
{
return date.HasValue ? date.Value.Date : (DateTime?)null;
}
Then you can then use that function in LINQ to Entities and LINQ to Objects and it will work. However, that method means that you would have to replace calls to EntityFunctions with calls to your new class.
Another, better (but more involved) option would be to use an expression visitor, and write a custom provider for your in-memory DbSets to replace the calls to EntityFunctions with calls to in-memory implementations.