I have a method which iterates through all the properties of an object. I am logging those properties:
Object obj = entry.Entity;
Type type = obj.GetType();
PropertyInfo[] properties = type.GetProperties();
foreach (PropertyInfo property in properties)
{
oldData.AppendFormat("{0}={1} || ", property.Name, property.GetValue(obj, null));
}
Now this is working fine but on my table log, it is also writing this properties below:
- PremiumReference=System.Data.Objects.DataClasses.EntityReference`1[Data.Premium]
- EntityState=Deleted
- EntityKey=System.Data.EntityKey
Any ideas how I can filter this properties?
Every Entity in Entity Framework has a property with the enumeration EntityState. EF adds them to the object.
If you add an Object to EF it marks it as EntityState.Added.
Hope it helps.
See Entity Framework EntityState
Have a look in here
BindingFlags-Enumeration
Maybe it helps using the flag DeclaredOnly in combination with the other flags you need in your scenario to match your needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With