抛出的异常信息为"New transaction is not allowed because there are other threads running in the session "
可能出现在的情况:
1、在循环中中没有将对象完全读入内存,每次只读取一行,在循环体内执行context.SaveChanges()时抛出异常
解决方法:将objectQuery或objectResut转换为List则可,或者在所在修改操作完成后,在循环体后面执行保存。
2、将ObjectQuery直接绑定到数据库控件后,在修改对象后,执行SaveChanges()抛出异常
解决方法: ObjectResult <Feature> result= _FeatureQuery.Execute(MergeOption.OverwriteChanges);
bindingChrSource.DataSource = result.ToList();
本文探讨了Entity Framework中出现的Newtransactionisnotallowedbecausethereareotherthreadsrunninginthesession异常, 并提供了两种常见情况下的解决方案。
4551

被折叠的 条评论
为什么被折叠?



