以下 LINQ 执行需要 90 毫秒的查询:
.Where(Function(i) (i.RequestedByUserId = MySession.ApplicationUserId)
And (i.RequestKey1 = searchJson)
And (i.RequestMethod = "ProjectPlanService.GetProjectPlanMaintenanceData"))
.Select(Function(i) i.ResultJson).FirstOrDefault
生成的 SQL 如下:
SELECT
[Limit1].[ResultJson] AS [ResultJson]
FROM ( SELECT TOP (1)
[Extent1].[ResultJson] AS [ResultJson]
FROM [dbo].[ApplicationCache] AS [Extent1]
WHERE ([Extent1].[RequestedByUserId] = 2) AND ([Extent1].[RequestKey1] = '{"SortProperty":"","SortOrder":0,"PageNumber":1,"RecordsPerPage":15,"CriteriaCount":"1","CriteriaString":"~=~Id"}') AND ('ProjectPlanService.GetProjectPlanMaintenanceData' = [Extent1].[RequestMethod])
) AS [Limit1]
- 如何优化上述 LINQ 表达式以减少执行时间?
- 有没有办法获得如下的单个 Select 语句:
SELECT
[ResultJson]
FROM [dbo].[ApplicationCache] AS [Extent1]
WHERE ([Extent1].[RequestedByUserId] = 2) AND ([Extent1].[RequestKey1] = '{"SortProperty":"","SortOrder":0,"PageNumber":1,"RecordsPerPage":15,"CriteriaCount":"1","CriteriaString":"~=~Id"}') AND ('ProjectPlanService.GetProjectPlanMaintenanceData' = [Extent1].[RequestMethod])