Thursday 8 June 2023

Error : The specified type member 'Date' is not supported in LINQ to Entities

I was trying to use Date property of DateTime field in LINQ query but got this error.

Message = "The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported."

Example query : 

var query = from employeeRecord in _context.EmployeeRecord 

                   where (employeeRecord.StartDate.Date== currentDate)

Solution : Use DbFunctions.TruncateTime to truncate time part from a DateTime.

Updated Query : 

var query = from employeeRecord in _context.EmployeeRecord 

                   where (DbFunctions.TruncateTime(employeeRecord.StartDate) == currentDate)

No comments:

Post a Comment