实施OnRaisePropertyChanged偏类OnRaisePropertyChanged、偏类

2023-09-06 15:27:41 作者:空欢喜

我用的EntityFramework生成的数据库类。在一些这些类的,我想从PropertyChangeBase继承来实现功能OnRaisePropertyChanged的一些属性。 因此,我修改了一些生成的类。前

I used entityframework to generate classes from database. In some of these classes, I'd like to inherit from PropertyChangeBase to implement function OnRaisePropertyChanged for some properties. Therefore, I modified on some generated classes. Ex

public partial class MyGeneratedClass : PropertyChangeBase
{
        private DateTime _lastUpdatedDate;
        public System.DateTime LastUpdatedDate
        {
            get { return _lastUpdatedDate; }
            set
            {
                _lastUpdatedDate = value;
                OnRaisePropertyChanged("LastUpdatedDate");
                OnRaisePropertyChanged("LastUpdatedDateFormat");
            }
        }
}

由于每次更新我的实体,我所有的code将overwrited。实现在部分类将引发一个编译错误。有没有办法解决这个?

Because everytime I update my entity, all my code will be overwrited. Implement in the partial class will raise an compile error. Is there a way to overcome this?

推荐答案

本的EntityFramework给部分方法可以充分实施。 由于所有生成的实体也在部分类,你基本上可以扩展你的实体,做任何你需要做的在那里。

The EntityFramework gives partial methods that can be fully implemented. As all generated entities are also partial classes, you can basically extend your entity and do what ever you need to do there.

请参阅这些文章,例如: code计划和的 P是局部

See these articles for example: Code Project and P is for partial

您便可以实现该接口,而不必担心具有code每次更新设计文件,以反映变化的时间打掉了。

You could then implement the interface and not worry about having the code wiped out every time you update the designer file to reflect changes.

相关推荐