0
我有一些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
为实体框架看http://stackoverflow.com/questions/6429594/command-timeout-with-entity-framework-4-1-code-first – hatchet