通过 EF 4.0Entity 更新我的表发生异常
我编写了这些代码来更新我的整个表重新排序我的 jobseqno:
protected void Update()
{
MyEntities ctx = new MyEntities ();
var qry = ctx.MyTable.Where(q => q.workorder == "100001076").OrderBy(q => q.id);
dataGridView1.DataSource = qry;
int i = 0;
foreach (var item in qry)
{
i++;
item.jobseqno = i.ToString();
ctx.SaveChanges();
}
}
如何更新我的整个表。我给出了新的号码收集 jobseqno。但发生错误:
EntityException 未处理
在提供程序连接上启动事务时发生错误。有关详细信息,请参阅内部异常:
异常:不允许新事务,因为会话中还有其他线程正在运行
i writed these codes to update my whole table re order my jobseqno:
protected void Update()
{
MyEntities ctx = new MyEntities ();
var qry = ctx.MyTable.Where(q => q.workorder == "100001076").OrderBy(q => q.id);
dataGridView1.DataSource = qry;
int i = 0;
foreach (var item in qry)
{
i++;
item.jobseqno = i.ToString();
ctx.SaveChanges();
}
}
How to update my whole table. i give new number collection jobseqno. But Error occured:
EntityException was unhandled
An error occurred while starting a transaction on the provider connection. See the inner exception for details:
Exception : New transaction is not allowed because there are other threads running in the session
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看这篇 博文,解决方案似乎是将从 MyTable 获取的元素存储到数组中,而不是直接使用 IEnumerable 结果。试试这个:
Looking over this blog post, the solution seems to be to store the elements you get from MyTable into an array, as opposed to working with the IEnumerable result directly. Try this: