我试图检索特定日期之前的所有记录,如下所示:
?$filter=CreatedDate lt '2020-06-04T14:27:12.38'
Run Code Online (Sandbox Code Playgroud)
但我一直收到这个错误
"message": "URI 中指定的查询无效。检测到类型不兼容的二元运算符。找到运算符类型 'GreaterThan' 的操作数类型 'Edm.DateTimeOffset' 和 'Edm.String'。",
我尝试投射日期
?$filter=CreatedDate lt cast('2020-06-04T14:27:12.38', Edm.DateTimeOffset))
Run Code Online (Sandbox Code Playgroud)
但还是一样。
也尝试过
?$filter=CreatedDate lt datetime'2020-06-04T14:27:12.38'
Run Code Online (Sandbox Code Playgroud)
并收到
URI 中指定的查询无效。无法识别“CreatedDate gt datetime”1995-09-01T00:00:00”中“21”处的“Edm.String”文字“datetime”1995-09-01T00:00:00”。
有办法实现这一点吗?
xin*_*ose 12
您必须查询不带引号的日期。我的应用程序的一个例子:
http://localhost/EDS4OData/EmployeeHoursVacationRequests?$filter=(Username eq 'jsmith' and DeleteInd eq false and DayOffType eq 2 and StartDate ge 2020-10-01T00:00:00.000Z and StartDate le 2020-12-31T23:59:59.999Z)&$count=true
Run Code Online (Sandbox Code Playgroud)
在我的控制器 C# 模型中:
public DateTime StartDate { get; set; }
Run Code Online (Sandbox Code Playgroud)