我们有一个使用EF代码首先调用的视图。它使用Linq语法并且很直接。工作一段时间后,查询在ToList方法超时。即使在那时,查询也可以立即从SSMS中运行。
注意到一件事是丢弃并重新创建视图解决了问题,但在无限期之后问题重新出现。
数据库位于SQL Azure上,并检查对象上的任何锁定,但未找到任何内容。
有没有人遇到过这样的问题或类似问题。你能帮忙吗???
被阻止的实际查询
var results = facilityId == Guid.Empty ?
(from c in Context.CallLists
where c.AgencyId == agencyId
select c)
:
(from c in Context.CallLists
where c.AgencyId == agencyId && c.InitiatedFacilityId == facilityId
select c);
if (request.Page > 0)
{
results = results.Skip((request.Page - 1) * request.PageSize);
}
return results.Take(request.PageSize);
答案 0 :(得分:0)
在IOrderedQueryable<T>
和.OrderBy()
之前致电Skip
,将其更改为Take
。我认为它目前正在从表中检索所有行。通常我会预料到an exception to be thrown,但我不确定为什么没有 - 你是否使用了结果?您是否尝试使用Page&gt;运行它? 0?
试试这个:
var results;
if (facilityId != Guid.Empty)
{
results = Context.CallLists.Where(c => c.AgencyId == agencyId).OrderBy(c => c.Something);
}
else
{
results = Context.CallLists.Where(c => c.AgencyId == agencyId && c.InitiatedFacilityId == facilityId).OrderBy(c => c.Something);
}
if (request.Page > 0)
{
results = results.Skip((request.Page - 1) * request.PageSize);
}
return results.Take(request.PageSize);
除此之外,您还需要提出一种处理SQL Azure瞬态错误的方法。这基本上是在SQL Azure中执行查询时可以抛出的错误子集,应该通过等待和重试操作来处理,通常会在重试之间等待时间增加,直到最终接受失败。详细了解here和here。