3

有人指出问题吗?不断收到“LINQ to Entities 不支持指定类型成员‘日期’。仅支持初始化程序、实体成员和实体导航属性。”

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;
}                         
4

2 回答 2

2

从您的方法中删除所有内容,.Date但是:

DateTime reminderDate = DateTime.Today.Date;

EntityFramework 不支持.Date. Datetime出于这个原因,有伪函数EntityFunctions.TruncateTime,并且reminderDate你已经删除了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;
}
于 2013-08-15T07:54:42.810 回答
0

尝试这个

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

    return apps;
}          
于 2013-08-15T08:03:02.453 回答