我正在尝试加快代码执行速度,因此我想看看如果我执行异步操作,我的代码可以执行多快。
问题是在并行循环中我必须做一些检查,现在我正在执行延迟加载,我认为这会导致错误
A second operation started on this context before a previous operation completed.
现在我有这样的架构
TableATableB - many to many column
TableA - Can have many TableBs
TableB - Can have many TableAs
TableC - TableB can have many TableCs and TableC can only have 1 tableB
现在,我的代码死的问题是当我这样做的时候
foundTableBColumn.TableCs.Any()
我尝试进行急切加载,但遇到同样的问题
var foundTableBs = dbContext.TableATableB Include(x => x.TableB).ThenInclude(x => x.TableC).Where(x => x.TableAId == 1).Select(x => x.TableA).ToList();
Parallel.ForEach(foundTableBs , (tableB, loopState) =>
{
if(tableB.TableCs.Any(){
}
});