【问题标题】:Get Current Date filtered query through ASP.NET web api通过 ASP.NET web api 获取当前日期过滤查询
【发布时间】:2018-03-10 03:12:22
【问题描述】:

在我的程序中,我需要过滤适用于当月的时间表。我希望 json 结果与 Jquery 数据表绑定。我创建的get方法如下

 public IEnumerable<ScheduleDto> GetSchedules()
    {
        return _context.Schedules
.Where(x => DbFunctions.TruncateTime(x.PlannedStartDate.Date) >= DbFunctions.TruncateTime(System.DateTime.Now.Date))
                .Include(d => d.ResponsibleDepartment)
                .Include(e => e.EventCreatedBy)
                .Include(c => c.ScheduleCategory)
                .Include(y => y.ScheduleCriticality)
                .Include(v => v.EventEvaluatedBy)
                .Include(p=>p.Participants)
            .ToList()
            .Select(Mapper.Map<Schedule, ScheduleDto>);
    }

它的响应带有以下错误消息

“LINQ to Entities 不支持指定的类型成员“日期”。仅支持初始化程序、实体成员和实体导航属性。”

我做了一些 Stackoverflow 成员给出的建议。但问题仍然存在。 如果有人能找到错误,我非常高兴。

【问题讨论】:

    标签: c# asp.net-web-api entity-framework-6


    【解决方案1】:

    我发现了错误。只是因为我在查询中使用了.Date 属性。 Linq 引擎不支持 Date 属性。因此删除 Date 属性解决了我的错误。

    .Where(x => DbFunctions.TruncateTime(x.PlannedStartDate).Value >= DbFunctions.TruncateTime(DateTime.Now).Value)
    

    感谢所有花时间解决此问题的人。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-13
      • 2015-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      相关资源
      最近更新 更多