Collection was modified; enumeration operation may not execu 返回

var add = dbEvents.Except(cacheEvents, compare).ToList();
if (add.Count == 0)
{
return;
}
var extends = new List<TTrafficeventExtend>();
foreach (var e in add)
{
if (e.ExtendInfo == null)
{
trafficeventExtendManager.EventToExtend(e, TR_EventOP_Status.Add);
}
body.Add(GetMessage(e, TrafficEventOpType.Add));
}
if (extends.Count > 0)
{
await context.Insertable<TTrafficeventExtend>(extends).ExecuteCommandAsync();
}
var eventIds = add.Select(s => s.EventID).ToList();
// 报错位置
add = context.Queryable<TTrafficevent>()
.Includes(e => e.ExtendInfo)
.Where(e => eventIds.Contains(e.EventID)).ToList();
var temp = add.Select(s => new ThridTraffcEventMessage
{
Event = s,
OpType = TrafficEventOpType.Add,
}).ToList();
堆栈
at System.ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion() in System\ThrowHelper.cs:line 277
at System.Collections.Generic.List`1.Enumerator.MoveNextRare() in System.Collections.Generic\List.cs:line 69
at System.Linq.Enumerable.WhereListIterator`1.MoveNext()
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
at SqlSugar.SqlSugarProvider.InitMappingInfo(EntityInfo entityInfo) in SqlSugar\SqlSugarProvider.cs:line 397
at SqlSugar.SqlSugarProvider.InitMappingInfo(Type type) in SqlSugar\SqlSugarProvider.cs:line 353
at SqlSugar.SqlSugarProvider.InitMappingInfo[T]() in SqlSugar\SqlSugarProvider.cs:line 346
at SqlSugar.SqlSugarProvider.Queryable[T]() in SqlSugar\SqlSugarProvider.cs:line 923
at SqlSugar.SqlSugarClient.Queryable[T]() in SqlSugar\SqlSugarClient.cs:line 724
热忱回答(4)
-
岁月留歌画山 VIP0
1个月前"SqlSugarCore" Version="5.1.4.162"
0 回复 -
fate sta VIP0
1个月前线程安全问题
文档:偶发
0 回复 -
fate sta VIP0
1个月前context.CopyNew().Queryable<TTrafficevent>()
await context.CopyNew().Insertable<TTrafficeventExtend>(extends).ExecuteCommandAsync();
报错代码都加上copynew,
0 回复 -
岁月留歌画山 VIP0
1个月前@fate sta:每次查询都需要copyNew吗,现在我这里每次调用该定时任务方法入口时,copyNew()一次,定时任务方法内,context时共用的
0 回复