I have an Entity Data Model that is made up of these multiple entities - Vendor, Payment, VendorContact, Invoice and GLAccount. I am using EF version 4.
In some existing code there are 5 methods being called one after the other, and these are saving changes for the above entity tables in database. The methods are as described below.
- Method1 changes data for a certain Vendor object in memory and then calls SaveChanges method on object context.
- Method2 changes data for Payments objects and calls SaveChanges.
- Method3 changes data for VendorContacts objects and calls SaveChanges.
- Method4 changes data for Invoices objects and calls SaveChanges.
- Method5 changes data for GLAccounts objects and calls SaveChanges.
My question is: Would I gain much in performance if I called SaveChanges method only once Vs calling it five times? Right now, Method1 thru to Method5 are taking about 25 seconds to complete.
So my proposal is to remove SaveChanges from all the methods and call SaveChanges only after Method5 call is done.