开发者

Several SubmitChanges in succession very slow

One question: Why when I use following code

 for (int i = 0; i < 10000; i++)
  {
      Entity e = new Entity();
      e.DisplayValue = i.ToString();
      ctx.Entities.InsertOnSubmit(e);
  }
  ctx.SubmitChanges();

it finishes after about 8 seconds

开发者_如何学JAVAbut when I use this code

 for (int i = 0; i < 10000; i++)
  {
      Entity e = new Entity();
      e.DisplayValue = i.ToString();
      ctx.Entities.InsertOnSubmit(e);
      ctx.SubmitChanges();
  }

it finishes after about 50 seconds

How can I do faser second example, because it is more situable for me?


Each time you call SubmitChanges, Linq-to-Sql is checking every object for tracked changes, so making the change to 1 object, but then iterating that same change 10000 times and calling SubmitChanges will exponentially increase the time it takes as Linq-to-Sql to process the changes because you are adding an extra item each time.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜