以下LINQ执行查询,执行时间为90毫秒 .Where(Function(i)(i.RequestedByUserId = MySession.ApplicationUserId)And(i.RequestKey1 = searchJson)And(i.RequestMethod =“ProjectPlanService.GetProjectPlanMaintenanceData”))。选择(Function(i)i.ResultJson).FirstOrDefault
生成的SQL如下:
选择 [Limit1]。[ResultJson] AS [ResultJson] FROM(选择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]
(1)如何优化上述LINQ表达式以减少执行时间?
(2)有没有办法获得如下的单一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])
答案 0 :(得分:0)
1:没有必要进行优化,它就好了 - 额外的“包装”不会改变任何东西。
2:它正在做一个前1,因为你要求FirstOrDefault(),如果你想要一个完整的结果列表不这样做。