简体   繁体   English

如果“从&到”日期是同一记录,则不过滤LINQ

[英]If From & To date is same record not filtering LINQ

I am filtering records based on Dates using Where clause but it's not working. 我正在使用Where子句基于Dates过滤记录,但是它不起作用。 From and To date is same & one record comes within the same date but that getting eliminates. “从”和“ 到”日期是相同的,并且在同一日期有一条记录,但是该记录被消除了。

todate {11/6/2018 12:00:00 AM} //while debugging 至今{11/6/2018 12:00:00 AM} //正在调试

if (toDate != "0")
{
    var todate = DateTime.Parse(toDate).Date;
    query = query.Where(x => x.CreatedDate.Date <= todate);
}
var homework = query.Select(x => new StudentHomework
{
    HomeworkId = x.HomeworkID,
    CreatedDate = x.CreatedDate
}).OrderByDescending(i => i.CreatedDate).Skip(pageLong * recordLong - recordLong).Take(recordLong);
return homework.Any()
    ? Request.CreateResponse(HttpStatusCode.OK, homework)
    : Request.CreateResponse(HttpStatusCode.NoContent);

From db coming one record to controller while debugging in VS 在VS中进行调试时,从数据库到控制器的一条记录

在此处输入图片说明

But query is showing 0 records & in ResulView getting below messages 但是query显示0条记录并在ResulView中显示以下消息

Message = "The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported. Message =“ LINQ to Entities不支持指定的类型成员'Date'。仅支持初始化程序,实体成员和实体导航属性。

If I remove filter in my mobile app json result coming like this 如果我在移动应用程序json删除过滤器,结果如下

"HomeworkId": 1400,
"ClassName": "Class 1",
"SectionName": "N/A",
"SubjectName": "Mathematics",
"IsAnswered": false,
"CreatedDate": "2018-11-06T00:00:00",

First of all feeling stupid to wasting time of everyone by asking confusing question. 首先,通过问一个令人困惑的问题,浪费时间浪费每个人都是愚蠢的。 Here the issue was this line's .Date 这里的问题是该行的.Date

query = query.Where(x => x.CreatedDate.Date <= todate);

In LINQ to Entities I should not have .Date and it is not allowing throwing Exception . 在LINQ to Entities中,我不应该具有.Date并且不允许抛出Exception After removing this everything working fine. 删除后,一切正常。 I have try catch block but control was not jumping to it. try catch块,但控制权没有跳到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM