Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ WHERE DATE Issue [duplicate]

Anyone point out the issue? Keep getting "The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported."

public IEnumerable<Appointment> FindAllAppointmentsWithReminders()
{
    DateTime reminderDate = DateTime.Today.Date;
    IEnumerable<Appointment> apps = RepositorySet    
        .OfType<Appointment>()
        .Include("Client")
        .Where(c => EntityFunctions.TruncateTime(c.Client.Reminder.Date) == reminderDate.Date 
                        && reminderDate.Date > EntityFunctions.TruncateTime(c.StartTime.Date));

    return apps;
}                         
like image 877
D-W Avatar asked Jun 04 '26 05:06

D-W


1 Answers

Remove all the .Date from your method but this:

DateTime reminderDate = DateTime.Today.Date;

EntityFramework doesn't support the .Date property of Datetime. For this reason there is the pseudo-function EntityFunctions.TruncateTime, and for the reminderDate you already remove the time in the DateTime reminderDate = DateTime.Today.Date.

public IEnumerable<Appointment> FindAllAppointmentsWithReminders()
{
    DateTime reminderDate = DateTime.Today.Date;
    IEnumerable<Appointment> apps = RepositorySet    
        .OfType<Appointment>()
        .Include("Client")
        .Where(c => EntityFunctions.TruncateTime(c.Client.Reminder) == reminderDate 
                        && reminderDate > EntityFunctions.TruncateTime(c.StartTime));

    return apps;
}
like image 133
xanatos Avatar answered Jun 05 '26 18:06

xanatos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!