实体框架 - 如何提高OnChanging任何财产? [英] Entity Framework - how to raise OnChanging for any property?

查看:204
本文介绍了实体框架 - 如何提高OnChanging任何财产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个WPF / EF4.0 / MVVM应用程序,我有一个观点,即一个编辑Customer实体。什么是作用于OnChanging我CustomerViewModel短设置属性布尔IsCustomerInEditMode最好的办法/部分调用onChanged方法实体的每一个个人财产?据我知道有没有OnEntityChanging方法...

In a WPF / EF4.0 / MVVM app I have a View that edits a Customer entity. What is the best way to set a property "bool IsCustomerInEditMode" in my CustomerViewModel short of acting upon OnChanging/OnChanged partial methods for every single individual property of the Entity? As far as I know there's no OnEntityChanging method...

感谢

编辑:答:EntityState

Answer: EntityState

推荐答案

编辑:
要回答你在帖子中的问题(设置布尔IsCustomerInEditMode最好的方法) -

To answer your question in your post (best way to set bool IsCustomerInEditMode) -

订阅entity.PropertyChanging事件,它里面设置IsCustomerInEditMode ==真;
订阅entity.PropertyChanged事件,它里面设置IsCustomerInEditMode ==虚假;

Subscribe to the entity.PropertyChanging event, inside it set IsCustomerInEditMode == true; Subscribe to the entity.PropertyChanged event, inside it set IsCustomerInEditMode == false;

我觉得InstanceOfYourCustomer.PropertyChanging和InstanceOfYourCustomer.PropertyChanged你正在寻找的事件对于。关于你的实体每次生成的属性,事件触发,如果属性改变的(除非您使用部分类附加属性添加到您的实体,在这种情况下,你需要调用这些属性的制定者添加到ReportPropertyChanging和ReportPropertyChanged )。

I think InstanceOfYourCustomer.PropertyChanging and InstanceOfYourCustomer.PropertyChanged the events you're looking for. For every generated property on your entity, the event fires if a property changes (unless you use partial classes to add additional properties to your entity, in which case, you'll need to add calls to ReportPropertyChanging and ReportPropertyChanged in the setters of those properties).

http://msdn.microsoft.com/en-us/library/system.data.objects.dataclasses.structuralobject.propertychanged.aspx

的http:/ /msdn.microsoft.com/en-us/library/system.data.objects.dataclasses.structuralobject.propertychanging.aspx

我使用EF4 ,看着我的Model.Designer.cs文件......我所有的实体属性制定者的来电ReportPropertyChanging和ReportPropertyChanged ...这将激发你的实体PropertyChanging和的PropertyChanged事件和ARGS甚至会告诉你哪些具体财产是引发Changed事件。

I'm using EF4, and looking at my Model.Designer.cs file... all of my entities' properties' setters call ReportPropertyChanging and ReportPropertyChanged... which will fire the PropertyChanging and PropertyChanged events on your entity, and the args will even tell you which specific property it was that raised the changed event.

这篇关于实体框架 - 如何提高OnChanging任何财产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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