【发布时间】:2016-01-17 02:35:12
【问题描述】:
我的 Linq 查询超时,结果永远不会被检索到..
using (var repository = PersistenceService.GetRepository<Organisation>(UserId))
{
var organisation = repository.GetAll().FirstOrDefault(x => x.Id == organisationId);
if (organisation != null)
{
isCourseApproverRole = organisation.Contacts.FirstOrDefault(con => con.RoleName == "CourseApprover" &&
con.Individual.Id == individualId) != null;
}
}
当我尝试在一个查询中完成所有这些工作时,它工作正常.. 有人能解释一下为什么上面的查询会超时吗??
注意:organization.Contacts 包含所选组织的大约 18,000 行。
【问题讨论】:
-
看看生成的SQL语句就知道了。
-
打开 sql profilere 然后运行您的项目检查生成的 sql 查询类型,您可以更改您的 sql 查询
标签: asp.net-mvc linq c#-4.0 linq-to-sql