【发布时间】:2012-06-23 03:46:17
【问题描述】:
我有一个运行非常缓慢的 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);
【问题讨论】:
-
我会检查实际的 SQL 命令。也许一些查询执行了多次,或者 EF 创建了一些疯狂的子查询?
-
这是个好建议。我使用 SQLCOmpact 版本进行开发,但现在切换到 SQL Server 2008R2 后似乎快了很多。
标签: c# asp.net-mvc-3 linq entity-framework