So you instantiate an EF context, push objects in or pull objects out, it tracks the complete state of the object changes (if change tracking on). Up until this point the developer has been responsible for making these modifications. But once SaveChanges is called, all of these records are submitted in bulk and the developer is disenfranchised from the final result, save an error message on error or a successful call on completion.
Is there a way to customize the SaveChanges process so that it’s not such a black box? Ideally, being able to customize the process would really open up things for me, especially with my application architecture.
Thanks.
Handling
SavingChangesevent is one way but for more complex handling you can overrideSaveChangesoperation itself in your derived context. The difference is that inSavingChangesyou can put custom logic beforeSaveChangesdo its job but when overridingSaveChangesyou can put custom logic before and after callingbase.SaveChanges. There is not better support for custom logic during saving. Using custom SQL for saving is only possible if you map stored procedures to data modification operations of your entities.