I am using LINQ to Entities to retrieve item purchase dates as follows:
where EntityFunctions.TruncateTime(order.PurchaseDate) == myPurchaseDate.date
The key here is that the DB column contains the Date and Time so the time must be stripped for the compare. This code works fine.
Now, I want to do the same thing using dynamic LINQ to Entities. I am using dynamic.cs from the VS2010 code samples folder. When I code:
.where("EntityFunctions.TruncateTime(PurchaseDate) == @0", myPurchaseDate.date);
or any variant of same I get an error message. What do I have to code as the string value to make this work? (Since I can use .StartsWith or .Contains inside the string I am hoping there is some date function dynamic LINQ will recognize).
I know I can create the dynamic LINQ query to be a date range, conceptually:
PurchaseDate >= myPurchaseDate@midnight and PurchaseDate <= myPurchaseDate+23:59:59
In fact, maybe a date range is more efficient from a SQL Server perspective but I would like to know if something like TruncateTime or ToShortDate exists within Dynamic LINQ to Entities.