0

I am coding a MVC 5 internet application and am using Entity Framework 6. I have an Asset object that can be referenced in many Image objects.

When I edit an Asset object, I need to update a DateTime object that is stored in all referenced Image objects. If there are 50 Image objects that need to be updated, can I do this in one database transaction rather than retrieving the Image objects, looping through each Image object, updating the DateTime object and then updating each Image object in the database?

Thanks in advance.

Simon
  • 7,991
  • 21
  • 83
  • 163

1 Answers1

0

As far as I am aware if you loop through and update each but call context.saveChanges() after the loop it should commit in one transaction as the transaction is not done until saveChanges is called.

Dhunt
  • 1,584
  • 9
  • 22
  • How can I check if this is the case? – Simon Apr 01 '15 at 12:11
  • You could open SQL management studio connect to your db then go to tools>sql server profiler. This will show all db transactions, if only one is executed after the loop then you should only see one. Debug into the saveChanges line in break there. When you step on you should see the transaction in profiler. – Dhunt Apr 01 '15 at 12:14