Entity Framework SaveChanges - Customize Behavior?

前端 未结 1 482
心在旅途
心在旅途 2021-01-23 15:08

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 devel

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-23 15:30

    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.

    0 讨论(0)
提交回复
热议问题