How to raise PropertyChanged event on lazy loaded properties

c# entity-framework-6 inotifypropertychanged lazy-loading wpf

Accepted Answer

I've just realised that, oh.virtual that it is capable of having a body, and fortunatelyEntityFramework calls that body once lazy loading is complete, hence this was successful.

[Table("Bills")]
public class Bill : NotifyBase
{
    //works !!
    private Discount m_Discount;
    public virtual Discount Discount
    {
        get { return m_Discount; }
        set { SetWithNotif(value, ref m_Discount); }
    }


}

[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;
}
0
9/5/2017 6:00:08 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow