实体框架4:ObjectContext事件成功保存 [英] Entity Framework 4: ObjectContext event on successful save

查看:181
本文介绍了实体框架4:ObjectContext事件成功保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一个好的方法来检测何时实际提交了 ObjectContext 更改?

Is there a good way to detect when the ObjectContext changes are actually committed?

SavingChanges 发生在进入数据存储之前,但我还需要一种方法来知道这些更改是否实际提交。

SavingChanges occurs before going to the data store but I also need a way to know if those changes where actually committed.

提前感谢
John

Thanks in advance John

更新:

我有一个代码首先是DbContext。这被馈送到动态数据,正如我发现使用DbContext的内部ObjectContext(当转换到IObjectContextAdapter时,我可以访问它)。不调用dbcontext的SaveChanges,而是使用objectcontext的SaveChanges。所有我想要做的是在保存完成后通知(即事件SavedChanges),所以我可以使我的缓存无效。

What I have is a code first DbContext. This is fed into dynamic data which as I discovered uses the DbContext's internal ObjectContext (to which I have access when casting to IObjectContextAdapter). The dbcontext's SaveChanges is not called, the objectcontext's SaveChanges is used instead. All I want to do is to be notified after the save is complete (i.e. event SavedChanges) so I can invalidate my cache.

推荐答案

没有内置事件来处理它,但是您可以在派生上下文中覆盖 SaveChanges 方法,并在调用 base.SaveChanges

There is no build-in event to handle this but you can override SaveChanges method in your derived context and fire any custom event specific to your own context type after you call base.SaveChanges.

这篇关于实体框架4:ObjectContext事件成功保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆