Skip to content

Instantly share code, notes, and snippets.

@danstuken
Created August 29, 2012 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danstuken/3517864 to your computer and use it in GitHub Desktop.
Save danstuken/3517864 to your computer and use it in GitHub Desktop.
Update EF Entity
public static class EntityExtensions
{
public static void MergeChanges<TEntity>(this TEntity targetEntity, TEntity sourceEntity) where TEntity: IPersistable
{
var publicWritableProps = typeof(TEntity).GetProperties(BindingFlags.Instance | BindingFlags.Public);
foreach (var prop in publicWritableProps)
{
if (prop.Name != "PersistenceKey")
{
var newValue = prop.GetValue(sourceEntity, null);
prop.SetValue(targetEntity, newValue, null);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment