Reputation: 1330
When tried to condition the where statement to only compare the date part of the datetime field using this code,
var list = products.Where(x => ((DateTime)x.PurchaseDate).Date >= dt_SelectDate.Value.Date);
I used the (DateTime)
conversion because EF don't recognize the .GetValueOrDefault()
, and the PurchaseDate
field is nullable.
the error I got is
The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
Upvotes: 2
Views: 1502
Reputation: 308
I think you need to the the EntityFunctions.TruncateTime method to compare (just) dates.
Here's the MSDN description: http://msdn.microsoft.com/en-us/library/dd395596.aspx
Upvotes: 4