开发者

Updating my table via EF 4.0Entity Exception occured

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 starti开发者_StackOverflowng 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


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:

var qry =
   ctx.MyTable
       .Where(q => q.workorder == "100001076")
       .OrderBy(q => q.id)
       .ToArray<MyTable>; // save it as a local array
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜