"The specified type member 'Date' is not supported in LINQ "

_dbEntities.EmployeeAttendances.Where(x => x.DailyDate.Date.Equals(DateTime.Now.Date)).ToList();

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

How can i do this get employees data on based on current date in linq query?

Jon Skeet
people
quotationmark

If the DailyDate property is already just a date, instead of a date and time, then it would be simplest to just use:

// Outside the query so it becomes a constant, effectively
var today = DateTime.Today;
var employees = _dbEntities.EmployeeAttendances
                           .Where(x => x.DailyDate == today)
                           .ToList();

If it does have times (making the above fail), you could always use:

// Outside the query so it becomes a constant, effectively
var today = DateTime.Today;
var tomorrow = today.AddDays(1);
var employees = _dbEntities.EmployeeAttendances
                           .Where(x => x.DailyDate >= today &&
                                       x.DailyDate < tomorrow)
                           .ToList();

... or use TruncateTime as Farhad's answer suggests. I'd still recommend evaluating DateTime.Today first though:

var today = DateTime.Today;
var employees = _dbEntities.EmployeeAttendances
                       .Where(x => EntityFunctions.TruncateTime(x.DailyDate) == today)
                       .ToList();

Note that Today (like DateTime.Now) uses the system default time zone. You should think carefully about whether that's what you want.

people

See more on this question at Stackoverflow