我有一个运行非常缓慢的 LINQ to Entity 查询。此查询在特定数据库上执行一些计算逻辑,然后将结果传递给 ViewModel。查询非常快,直到我在查询底部添加了 4 个选择语句。我需要选择语句才能返回结果响应的集合。为什么查询运行这么慢?
var data = from SurveyResponseModel in db.SurveyResponseModels
group SurveyResponseModel by SurveyResponseModel.MemberId into resultCount
select new ResultsViewModel()
{
YesBarriersOthersResult = resultCount.Select(r => r.YesBarriersOthers),
NoBarriersOthersResult = resultCount.Select(r => r.NoBarriersOthers),
TotalResponsesResult = db.SurveyResponseModels.Count(),
};
return View(data);