新的交易是不允许的,因为在会议LINQ到实体运行的其他线程 [英] New transaction is not allowed because there are other threads running in the session LINQ To Entity

查看:308
本文介绍了新的交易是不允许的,因为在会议LINQ到实体运行的其他线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是这可能是为什么分手?

Any ideas on why this could be breaking?

foreach (var p in pp)
{
    ProjectFiles projectFile = (ProjectFiles)p;
    projectFile.Status = Constants.ProjectFiles_ERROR;
    projectFile.DateLastUpdated = DateTime.Now;
    context.SaveChanges();
}



我读了解决办法的问题,是检索一气呵成结果前foreach循环。

I read that the workaround the issue, is to retrieve the results in one go before the foreach loop.

但没有我这样做呢? PP是在我的案件结果的收集

But didnt I do that? "pp" is the collection of results in my case

推荐答案

变量不是对象的集合,它是一个枚举可以返回的对象。当你使用枚举,源必须保持开放。

The pp variable isn't a collection of objects, it's an enumerator that can return objects. While you use the enumerator, the source has to remain open.

使用了ToList 的方法来实现枚举成集合。这将宣读了枚举所有项目,靠近源的连接,这样就可以使用其他的东西连接。

Use the ToList method to realise the enumerator into a collection. That will read all items from the enumerator and close the connection to the source, so that you can use the connection for other things.

foreach (var p in pp.ToList())

这篇关于新的交易是不允许的,因为在会议LINQ到实体运行的其他线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆