I am using LINQ to Entities to retrieve item purchase dates as follows:
where EntityFunctions.TruncateTime(order.PurchaseDate) == myPurchaseDate.date
Here is a link that lists EF4 functions that map to sql functions
Conceptual Model Canonical to SQL Server Functions Mapping
If your queries will often search by just the date aspect, another approach to consider, if available with your SQL Server database, would be to redundantly store a truncated version of the datetime column, in a date column type. See http://msdn.microsoft.com/en-us/library/bb630352.aspx).
All of your queries can then perform better because there are no conversions necessary, are less prone to developer error. And they're easier to query in plain old SQL as well.
Your EF queries would then query on the SQL Server date column
I recently started using dynamic linq for a project and also wanted to compare dates without the time component. Microsoft's dynamic linq C# sample code (Dynamic.cs) supports a fixed set of types, and EntityFunctions isn't one of them.
But with a little experimentation, I found that just adding EntityFunctions to the array of predefined types enables the use of TruncateTime and likely other EntityFunctions methods too.
Here's what the Dynamic.cs predefinedTypes array looks like in my project:
static readonly Type[] predefinedTypes = {
typeof(Object),
typeof(Boolean),
typeof(Char),
typeof(String),
typeof(SByte),
typeof(Byte),
typeof(Int16),
typeof(UInt16),
typeof(Int32),
typeof(UInt32),
typeof(Int64),
typeof(UInt64),
typeof(Single),
typeof(Double),
typeof(Decimal),
typeof(DateTime),
typeof(TimeSpan),
typeof(Guid),
typeof(Math),
typeof(Convert),
typeof(System.Data.Objects.EntityFunctions) // JimM
};
With this modified Dynamic.cs file, I'm able to create dynamic linq queries including expressions like the PurchaseDate example in your question.
I think you are going to want to go with the date range so that you can take advantage of indexing on the server if you need to. If you base your select statement on a calculated field, it will need to scan the table for each query.