我有一个Web API,该Web API使用Odata来通过Entity框架查询Dbset,并且需要使用compare(>或<)运算符来参数化日期值的帮助。
控制器以 [EnableQuery] 属性修饰。传递给$ filter查询的值为-
OpenDate gt 2019-07-01T00:00:00.0000000Z和OpenDate lt 2019-07-10T00:00:00.0000000Z和SponsorStatus eq 1和AccountStatus 等于'0'
执行的EF查询是
Opened connection at 7/9/2019 6:16:41 PM -04:00
SELECT TOP (@p__linq__2)
blah....
FROM ( SELECT
same blah...
FROM (SELECT
same blah...
FROM [Account].[AccountDetails] AS [AccountDetails]) AS [Extent1]
WHERE ([Extent1].[OpenDate] > convert(datetime2, '2019-06-30 20:00:00.0000000', 121)) AND ([Extent1].[OpenDate] < convert(datetime2, '2019-07-09 20:00:00.0000000', 121)) AND ( CAST( [Extent1].[SponsorStatus] AS int) = @p__linq__0) AND (([Extent1].[AccountStatus] = @p__linq__1) OR (([Extent1].[AccountStatus] IS NULL) AND (@p__linq__1 IS NULL)))
) AS [Project1]
ORDER BY [Project1].[CFNAccountId] ASC
我也希望上面的OpenDate部分也被参数化,以便固定查询计划。知道如何实现吗?