0

Entity Framework를 사용하고 있으며 변경된 속성이 매핑되어있는 경우 속성을 업데이트하려는 속성 변경 이벤트를 트리거하고 있습니다.Entity Framework - 속성이 매핑되었는지 확인

protected void FooPropertyChanged(object sender, PropertyChangedEventArgs e) 
{ 
    var notMappedArray = typeof(Foo).GetProperty(e.PropertyName).GetCustomAttributes(typeof(NotMappedAttribute), false); // I thought this might return null if the property did not have the attribute. It does not. 
    //if (notMappedArray == null) 
    UnitOfWork.Value.GetRepository<Foo>().Update(MyFoo); 
} 

이 이벤트로 보낸 속성이 엔티티 프레임 워크에 매핑되어 있는지 확인하는 가장 좋은 방법은 무엇입니까?

편집 : this question을 보았습니다. 그러나 그 대답은 조금 지나치게 빠져 나가는 것처럼 보이고, 내가 필요한 것을하지는 않습니다.

답변

1

내 Foo 클래스에 문제가있었습니다. 나는 명백하게 내가 확인하고 있던 속성 위에 부동 [NotMapped] 속성을 가졌다. 나는 다음과 같은 것을 사용했다.

protected void FooPropertyChanged(object sender, PropertyChangedEventArgs e) 
{ 
    var notMapped = typeof(Foo).GetProperty(e.PropertyName).GetCustomAttributes(typeof(NotMappedAttribute), false); 
    if (notMapped.Length == 0) 
    { 
     UnitOfWork.Value.GetRepository<Foo>().Update(MyFoo); 
    } 
}