c# - LINQ WHERE 日期问题

标签 c# linq entity-framework

<分区>

有人指出这个问题吗? 不断收到“LINQ to Entities 不支持指定的类型成员‘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.Date) == reminderDate.Date 
                        && reminderDate.Date > EntityFunctions.TruncateTime(c.StartTime.Date));

    return apps;
}                         

最佳答案

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

DateTime reminderDate = DateTime.Today.Date;

EntityFramework 不支持 Datetime.Date 属性。为此,存在伪函数 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;
}

关于c# - LINQ WHERE 日期问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18248384/

相关文章:

c# - 桥接来自两个绑定(bind)源的 DependencyProperty

c# - 如何读取使用 cmd.exe 运行的命令的输出

c# - 如何限制向 List<T> 添加项目?

c# - Linq to entity order by sql

c# - Entity Framework 多对象上下文

entity-framework - 将属性映射到 Entity Framework CTP5 中的(不同命名的)外键字段

C# 泛型列表联合问题

c# - Linq 查询 - 根据首字母黑白两个范围查找字符串

vb.net - Linq to Datarow,选择多个不同的列?

c# - Linq to Sql 查询,datediff +-3 天