The specified type member ‘Date’ is not supported in LINQ to Entities. Only initializers,…

When using EF, in the limda expression (query. Where (x = > x.CheckInDate >= bd.Date);) This exception is thrown when querying. The discovery found on the Internet can not solve the problem

Later, in http://sandeep-tada.blogspot.com/2014/02/the-specified-type-member-date-is-not.html It is found in that the datetime member date is not allowed in the original LINQ

To avoid this, there are two solutions:

1、 After assigning bd.date to LINQ, pass it in:

var bdDay = bd.Date;

query.Where(x => x.CheckInDate >= bdDay);

2、 Use the dbfunctions function method to escape

query.Where(x => x.CheckInDate >= DbFunctions.TruncateTime(bd.Date));

Similar Posts: