Entity Framework SaveChanges - Customize Behavior?
Asked Answered
P

1

1

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.

Parturifacient answered 23/7, 2011 at 2:38 Comment(2)
Could you look back at your question and rewrite it or something?\Duro
Is there a way to customize the SaveChanges process so that it's not such a black box? - that says it all... I don't like the way EF does it. It submits 100 changes without you really knowing what's going on...Parturifacient
W
3

Handling SavingChanges event is one way but for more complex handling you can override SaveChanges operation itself in your derived context. The difference is that in SavingChanges you can put custom logic before SaveChanges do its job but when overriding SaveChanges you can put custom logic before and after calling base.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.

Wertheimer answered 23/7, 2011 at 9:32 Comment(1)
This is correct. I failed to mention this, and this was the method I meant to give. I've deleted my answer. Have an upvote!Sussman

© 2022 - 2024 — McMap. All rights reserved.