实体模型在数据更改时会触发事件吗? [英] Does an entity model fire an event when its data changes?

查看:60
本文介绍了实体模型在数据更改时会触发事件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当实体模型表示的特定表中的数据发生更改时,我想收到通知。模型是否了解基础数据更改?如果确实触发了事件,我该如何订阅它?

I want to be notified when data changes within a particular table, represented by an entity model. Is the model aware of underlying data changes? If it does actually fire an event, how can I subscribe to it?

推荐答案

您的问题实际上还不清楚。

Your question is actually very unclear.


我想在实体模型所代表的特定表中数据发生变化时得到通知。

I want to be notified when data changes within a particular table, represented by an entity model.

是什么意思?

是否希望收到有关您的应用程序未完成的数据库更改的通知?那么答案是:没有EF不提供任何此类通知系统。您必须构建自己的数据库。

Do you want to be notified about changes in database not done by your application? Then the answer is: No EF doesn't provide any such notification system. You must build your own.

是否要收到关于对实体所做的更改的通知?答案是 INotifyPropertyChanged 接口和 ObservableCollectio n以获得导航属性。在实体中使用这些构造以能够在实体更改时触发事件。

Do you want to be notified about changes you did to your entities? The the answer is INotifyPropertyChanged interface and ObservableCollection for navigation properties. use these constructs in your entities to be able to fire events when entity changes.

您是否想知道数据库中将执行哪些更改?覆盖 SaveChanges 或处理 SavingChanges 并使用 ObjectStateManager 获取列表更改的实体。 此处是如何获取以下对象的已添加实体列表的示例给定类型。

Do you want to know what changes will be executed in the database? Override SaveChanges or handle SavingChanges and use ObjectStateManager to get list of changed entities. Here is some example how to get list of added entities of given type.

这篇关于实体模型在数据更改时会触发事件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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