0

I ve searched online to fix the insert performance issue related to the EF4. I just wonder why there is nothing like autodetectchangesenabled(> EF4) property exposed here in EF4 to improve the performance when the system is loaded with too much data.

I am doing load testing with following scenario. Lets say Students are attending online test with 50 questions and the backend logic has to update the score for 50 questions at the end of the test. number of students attending per session is 20000. In a day there are 5 sessions. The problem happens after 3rd session starts where time to update the score for the student takes more time. I know since entity framework keeps track of changes it is taking time to insert.

Please let me know how to handle this in entity framework 4.

Thanks In Advance, Murali K

  • `ObjectContext` doesn't have the automatic change detection when you insert an entity (and in other methods), hence there is no `AutoDetectChangesEnabled` flag like with `DbContext`. You can think of it like it were always `false`. So, your performance problem doesn't come from change detection. However, you can still apply the ideas from here (http://stackoverflow.com/a/5942176/270591) (call `SaveChanges` after a few hundred items, recycle context) or the `SqlBulkCopy` explained in other answers to that question. – Slauma Dec 19 '13 at 11:50
  • I'm not sure if I understand your scenario correctly: You are inserting 50*20000 = 1 million rows per session and that 5 times per day, right? And it gets slow with the 3rd session? But you don't keep a single context open a whole day, or do you? A sketch how your current code looks like would probably help to give you an answer. – Slauma Dec 19 '13 at 11:55
  • Thanks for clarifying me on ObjectContext entity tracking concept. – Murali Kothandaraman Dec 20 '13 at 06:20
  • To explain you more about the scenario,I am not doing bulk insert/update here. I won't update the DB in one shot for all 20000 user per session. I will update the score as when the student completes the test. So I can't/won't do context.SaveChanges() in one go for all 20,000 students in a session. But if multiple students complete the test at the same time,then I spawn new thread(Parallel.Foreach) for each completed student and then do an update. And also new context will be created and closed for each update scenario mentioned above. Do you see any problem with this approach? Thanks Murali K – Murali Kothandaraman Dec 20 '13 at 06:22

0 Answers0