如果 From & To date 是相同的记录不过滤 LINQ
If From & To date is same record not filtering LINQ
我正在使用 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
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);
在VS中调试时从db来一条记录到controller
但是 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.
如果我在我的移动应用程序中删除过滤器 json
结果会变成这样
"HomeworkId": 1400,
"ClassName": "Class 1",
"SectionName": "N/A",
"SubjectName": "Mathematics",
"IsAnswered": false,
"CreatedDate": "2018-11-06T00:00:00",
首先感觉很蠢,问了个乱七八糟的问题浪费大家的时间。这里的问题是这一行的 .Date
query = query.Where(x => x.CreatedDate.Date <= todate);
在 LINQ to Entities 中我不应该有 .Date
并且它不允许抛出 Exception
。删除后一切正常。我有 try
catch
块,但控件没有跳转到它。
我正在使用 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
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);
在VS中调试时从db来一条记录到controller
但是 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.
如果我在我的移动应用程序中删除过滤器 json
结果会变成这样
"HomeworkId": 1400,
"ClassName": "Class 1",
"SectionName": "N/A",
"SubjectName": "Mathematics",
"IsAnswered": false,
"CreatedDate": "2018-11-06T00:00:00",
首先感觉很蠢,问了个乱七八糟的问题浪费大家的时间。这里的问题是这一行的 .Date
query = query.Where(x => x.CreatedDate.Date <= todate);
在 LINQ to Entities 中我不应该有 .Date
并且它不允许抛出 Exception
。删除后一切正常。我有 try
catch
块,但控件没有跳转到它。