Mustafa Magdy
Mustafa Magdy

Reputation: 1330

Compare date part in where clause

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

Answers (1)

JimMat
JimMat

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

Related Questions