【问题标题】:LINQ to SQL GroupBy: connection timeoutLINQ to SQL GroupBy:连接超时
【发布时间】:2013-07-10 09:01:52
【问题描述】:

我只是写了一个我认为非常简单的查询:

public IList<Departement> GetDepartements()  
{
    IQueryable<MyContext> queryBase = QueryBase();

    IQueryable<Departement> query = 
        (from x in queryBase
         group x by x.Geographies.DepartementCode
         into grp
         select new Departement
             {
                 code = grp.Key,
                 numberOfDistributors =
                     grp.Select(x=> x.Distributors.Distributeur_PK)
                        .Count(),
                 numberOfLeads =
                     grp.Select(x=> x.Leads.DemandeWeb_FK).Count()
             }
        );
    return query.ToList();
}

很遗憾,我收到了连接超时错误。

我不想更改 DataContext.CommandTimeout 属性,因为我觉得这样一个简单的查询没有必要。

知道为什么会出现此错误吗?

【问题讨论】:

    标签: c# .net linq-to-sql connection-timeout


    【解决方案1】:

    启动 SQL Profiler 并捕获发送的 sql 命令。
    然后在 SQL Management Studio 中手动执行命令,然后可以看到执行它需要多长时间。它的运行时间可能会比您当前的 CommandTimeout 长。

    在此之后,您有两个选择:

    • 要么增加 CommandTimeout
    • 想出另一种解决方案,逐部分检索数据或提高查询本身的整体性能(索引、结构)

    【讨论】:

    • 谢谢,我会报告我的发现。
    猜你喜欢
    • 2015-01-23
    • 1970-01-01
    • 2012-02-16
    • 1970-01-01
    • 2012-10-24
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 2014-04-08
    相关资源
    最近更新 更多