【发布时间】:2017-09-05 05:41:24
【问题描述】:
所以我在实体和复杂类型之间有一个简单的关系,我想在复杂类型发生变化时通知实体,就像这段代码一样
[Table("Bills")]
public class Bill : NotifyBase
{
//how to call SetWithNotif when this changes ?
public virtual Discount Discount { get; set; }
}
[ComplexType]
public class Discount : NotifyBase
{
//some props in here
}
public class NotifyBase : INotifyPropertyChanged,INotifyPropertyChanging
{
public void SetWithNotif<T>(T val,ref T field,[CallerMemberName] string prop = "" )
{
if (!field.Equals(val))
{
PropertyChanging?.Invoke(this, new PropertyChangingEventArgs(prop));
field = val;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prop));
}
}
[field: NotMapped]
public event PropertyChangedEventHandler PropertyChanged;
[field: NotMapped]
public event PropertyChangingEventHandler PropertyChanging;
}
【问题讨论】:
标签: c# wpf entity-framework-6 lazy-loading inotifypropertychanged