Reputation: 2292
I'm using Entity Framework and am triggering a property changed event, where I'd like to update a property if the property that changed is mapped.
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);
}
What is the best way to find if a property sent to this event is mapped in entity framework?
Edit: I've seen this question. However, it seems like the answer is going a little overboard, and doesn't quite do what I need.
Upvotes: 3
Views: 2593
Reputation: 2292
My problem was in my Foo class. I apparently had a floating [NotMapped]
attribute far above the property I was checking. I ended up using something like this:
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);
}
}
Upvotes: 9