0

그래서 내가 엔티티와 복합 형 간의 간단한 관계가 게으른로드 속성을하여 PropertyChanged 이벤트를 발생하고, 나는를 신고하려는 경우이 코드어떻게

[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; 
} 

답변

0

에서와 같이 복합 유형 변경, 오, 난 그냥 virtual 그것이 몸과 게으른로드가 완료 몸 후에 것을 운이 좋게 EntityFramework 통화를 할 수 있다는 것을 의미 깨달았다, 그래서 이것은 완벽하게

[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; 
} 
근무