using (var attendanceContext = new AttendanceAppContext())
{
var compareLogin = attendanceContext.Attendances.FirstOrDefault(u =>
u.LoginDate == DateTime.Now.Date &&
u.Employee.Username == user.Username);
The code is continued and the compareLogin variable is used later but here an exception is thrown that says:
“The specified type member ‘Date’ is not supported in LINQ to Entities. Only initializer, entity members, and entity navigation properties are supported.
Please help and tell me how I should compare the dates from the database.
You may use TruncateTime function:
Also if
u.LoginDateis date without time in your database you may try to useDateTime.Todayinstead ofDateTime.Now.Date. If it doesn’t work just extract it into some variable (e.gvar today = DateTime.Today) and use it in your LINQ expression.