[英]Entity Framework - Check if property is mapped
我正在使用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);
}
查找發送到此事件的屬性是否在實體框架中映射的最佳方法是什么?
編輯:我已經看到了這個問題 。 但是,答案似乎有點過頭了,還不能完全滿足我的需要。
我的問題是在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);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.