Print Page | Close Window

Find all "hard" properties on entity

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2012
Forum Discription: For .NET 4.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=4606
Printed Date: 06-Sep-2025 at 6:51am


Topic: Find all "hard" properties on entity
Posted By: katit
Subject: Find all "hard" properties on entity
Date Posted: 20-Nov-2013 at 8:01am
I need to filter out entity properties to avoid navigation properties.

I'm writing audit code, which should store all changes and currently it fails on getting "Original" value of navigation property. I need to collect all properties even keys for navigation properties. How do I filter this list?

foreach (var property in modifiedEntity.GetType().GetProperties())
               {
                    var oldValue = modifiedEntity.EntityAspect.GetValue(property.Name, EntityVersion.Original).ToString();
                    var newValue = modifiedEntity.EntityAspect.GetValue(property.Name, EntityVersion.Current).ToString();

                    if (oldValue.Equals(newValue)) continue;

                    auditEntry.SYSAuditDetails.Add(new SYSAuditDetail
                        {
                            SYSAudit = auditEntry,
                            FieldName = property.Name,
                            OldValue = oldValue,
                            NewValue = newValue
                        });
               }



Replies:
Posted By: kimj
Date Posted: 20-Nov-2013 at 9:58am
You can use the metadata DevForce holds for the entity and its properties.  Something like this:
 
var metadata = entityManager.MetadataStore.GetEntityMetadata(modifiedEntity.GetType());
foreach (var p in metadata.DataProperties) {
  var oldValue = p.GetValue(modifiedEntity, EntityVersion.Original);
  var newValue = p.GetValue(modifiedEntity, EntityVersion.Current);
}
 
The DataProperties collection contains only data (non-navigation) properties.  The EntityMetadata also contains other information you might find useful - http://drc.ideablade.com/devforce-2012/bin/view/Documentation/model-examine - http://drc.ideablade.com/devforce-2012/bin/view/Documentation/model-examine .


Posted By: katit
Date Posted: 20-Nov-2013 at 10:17am
Thank you, this worked!



Print Page | Close Window