New Posts New Posts RSS Feed: getting an Entity Original and Current Versions
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

getting an Entity Original and Current Versions

 Post Reply Post Reply
Author
vijayaleads View Drop Down
Newbie
Newbie


Joined: 22-Feb-2011
Location: Minnesota
Posts: 1
Post Options Post Options   Quote vijayaleads Quote  Post ReplyReply Direct Link To This Post Topic: getting an Entity Original and Current Versions
    Posted: 22-Feb-2011 at 1:19pm
Hello,

I know that we can find the Current and Original values of a property in an Entity using the GetValue method
For Example if my Entity is an Address with properties First Line,ZipCode and State

i can write something like

Address.PropertyMetaData.ZipCode.GetValue(address,EntityVersion.Current) and Address.PropertyMetaData.ZipCode.GetValue(address,EntityVersion.Original) to get the current and original ZipCode

But what I want to find out is if there is a way to get the Original and Current values of the Entity (Address) instead of a property?

Thanks for the help,
Vijaya



Edited by vijayaleads - 22-Feb-2011 at 1:21pm
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 24-Feb-2011 at 12:53am

Hi Vijaya,

There's no specific method to accomplish that, but you could create one using reflection:
 
public Entity RetrieveEntity(Entity entity, EntityVersion version) {
  var entityType = entity.GetType();
  var resultEntity = Activator.CreateInstance(entityType);
  foreach (var entityProperty in EntityProperty.GetEntityProperties(entityType)) {
    if (entityProperty.GetType().Name.Contains(typeof(DataEntityProperty).Name)) {
      var value = ((DataEntityProperty)entityProperty).GetValue(entity, version);
      TypeDescriptor.GetProperties(resultEntity)[entityProperty.Name].SetValue(resultEntity, value);
    }
  }
  return (Entity)resultEntity;
}
 
However, note that the retrieved entity with the original or current values is a Detached entity with the same Id as the Entity you are trying to retrieve values from. (i.e. you shouldn't be trying to attach it to the EM)
 
Can you explain why you are trying to get the whole entity rather than the properties? Are trying to "roll back" the entity? (if that's the case the above wouldn't be the correct approach)
 
Please provide details on what you are trying to do, so I can better understand your issue and help you.
 
Silvio.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down