[英]Please help me optimizing this Linq statement
可以帮助我优化以下LINQ语句。 我正在使用NHibernate作为ORM。 该语句需要花费超过一分钟的时间来执行。 不需要那么多时间。
var inValidIntroductionDates = environment.IntroductionDateInfo.IntroductionDateDetails
.OrderByDescending(x => x.ApplicationDate)
.Where(x => x.VaccineDetail.Id == vaccine.Id &&
x.ViewInfo.Id == viewInfoDetail.ViewInfo.Id &&
x.MasterForecastInfo.Id == scenarioId &&
x.IsIntroductionDateValid == false)
.ToList();
谢谢
将Where
子句OrderByDescending
之前,以减少参与order by语句的记录数。 喜欢
var inValidIntroductionDates = environment.IntroductionDateInfo.IntroductionDateDetails
.Where( x => x.VaccineDetail.Id == vaccine.Id &&
x.ViewInfo.Id == viewInfoDetail.ViewInfo.Id &&
x.MasterForecastInfo.Id == scenarioId &&
x.IsIntroductionDateValid == false)
.OrderByDescending(x => x.ApplicationDate)
.ToList();
你也可以改变
x.IsIntroductionDateValid == false
至
!x.IsIntroductionDateValid
但这不会提高性能。 只是一个准备选项。
var inValidIntroductionDates = environment.IntroductionDateInfo.IntroductionDateDetails.Where(
x => x.VaccineDetail.Id == vaccine.Id && x.ViewInfo.Id == viewInfoDetail.ViewInfo.Id && x.MasterForecastInfo.Id == scenarioId && x.IsIntroductionDateValid == false).OrderByDescending(x => x.ApplicationDate).ToList();
首先找到,然后订购
要考虑的一些事情:
请让我们知道重点。
问候,迈克尔
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.