New Posts New Posts RSS Feed: Find all "hard" properties on entity
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Find all "hard" properties on entity

 Post Reply Post Reply
Author
katit View Drop Down
Senior Member
Senior Member


Joined: 09-Sep-2011
Posts: 146
Post Options Post Options   Quote katit Quote  Post ReplyReply Direct Link To This Post Topic: Find all "hard" properties on entity
    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
                        });
               }
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
katit View Drop Down
Senior Member
Senior Member


Joined: 09-Sep-2011
Posts: 146
Post Options Post Options   Quote katit Quote  Post ReplyReply Direct Link To This Post Posted: 20-Nov-2013 at 10:17am
Thank you, this worked!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down