此查询按月生成JavaScript图表的组数据。如果要分组3或4年的数据,则调用此查询的API当前需要大约6秒钟才能运行。
有没有一种方法可以使查询效率更高?
pp3
是项目列表,而zz
是按天计的项目预算数据。
public static IQueryable<CombinedProjectFinancialSummary_Min> planned_bargraph(IQueryable<int> pp3, OneView_PPM db)
{
var planned = from c in
(from x in pp3
join z in db.BudgetProfile on x equals z.ProjectRef
join bc in db.BudgetConfigs on z.ID equals bc.BudgetProfileId
join zz in db.Budgets on bc.Id equals zz.ConfigId
select new { SortDate = zz.MDate, Amount = zz.Cost }).ToList()
group c by
new { year = c.SortDate.Year, month = c.SortDate.Month }
into grp
select new CombinedProjectFinancialSummary_Min
{
year = grp.Key.year,
month = grp.Key.month,
monthName = DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(grp.Key.month),
xSeries = DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(grp.Key.month) + " " + grp.Key.year,
Amount = grp.Sum(t => t.Amount)
};
return planned.AsQueryable();
}
希望将其降低到2或3秒。
答案 0 :(得分:0)
我最终通过删除其中一个联接来减少查询时间
join z in db.BudgetProfile on x equals z.ProjectRef
这将执行时间从7秒减少到1.5秒。