2012-09-13 142 views
0

可能重複:
sql timeout expiredLINQ超時:超時過期

我有一些LINQ的代碼,我不敢肯定它做什麼。基本上我從一些表中抽出一份報告。這個linq語句試圖返回大約1.45分鐘的227106條記錄。當我從代碼中執行它,它是給我一個「超時」異常:

An error occurred while executing the command definition. See the inner exception for details. 
    at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) 
    at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues) 
    at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) 
    at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() 
    at System.Data.Entity.Internal.Linq.InternalQuery`1.GetEnumerator() 
    at System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator() 
    at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) 
    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) 
    at #####.Service.TrackingLogService.GetPastDayClickingReports(Guid AffiliateID, Int32 pastDays) in ... 

的代碼如下:

var temp = (from l in logs 
group l by new { l.AffiliateGUIDID, l.MarketingTool, l.RefereceURL } into g 
       select new ClickingReportItem 
       { 
        Name = g.Key.MarketingTool.Title, 
        MediaType = g.Key.MarketingTool.MediaType.Name, 
        RefereceURL = g.Key.RefereceURL, 
        Impressions = (g.Key.MarketingTool.ImpressionTracking.HasValue ? g.Key.MarketingTool.ImpressionTracking.Value : false) 
         ? g.Count(m => m.TrackingTypeID == (int)Contract.TrackingType.Impressions) : (int?)null, 
        Clicks = g.Count(m => m.TrackingTypeID == (int)Contract.TrackingType.Clicks), 
        Registrations = g.Count(m => m.TrackingTypeID == (int)Contract.TrackingType.Registrations), 
        Purchases = 0, 
        Commissions = 0 
       }).OrderByDescending(m => new { m.Registrations,m.Clicks,m.Impressions}).AsQueryable(); 
     return temp.ToList(); 

從幾個職位/博客我已經嘗試添加連接超時= 0到我的連接字符串,嘗試連接超時= 1800沒有用。

一些建議context.CommandTimeout = 240,但我不知道哪裏可以在我的代碼中應用CommandTimeout。

我在Linq不太好。

感謝

ClayCass

+0

爲實體框架看http://stackoverflow.com/questions/6429594/command-timeout-with-entity-framework-4-1-code-first – hatchet

回答