开发者

Business Logic when Saving in Entity Framework

开发者 https://www.devze.com 2023-01-28 00:47 出处:网络
If I want to perform some action when an entity is saved, I can do so开发者_Python百科mething as described here.

If I want to perform some action when an entity is saved, I can do so开发者_Python百科mething as described here.

However, suppose I retrieve an object from the database. This object has a list of items within it. If I instantiate a new item and add it to this list and then save all changes, the item in the list is not part of the "GetObjectStateEntries".


The problem for my situation, I believe, has been resolved. There appears to be a bug, in my opinion, in the ObjectContext.SaveChanges(SaveOptions) method. Even though this method will call DetectChanges (depending on the saveOptions), the OnSavingChanges method is called FIRST. This, I think, is a problem.

The solution to this is to call ObjectContext.DetectChanges() prior to calling SaveChanges().

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号