Created
August 29, 2012 19:47
-
-
Save danstuken/3517864 to your computer and use it in GitHub Desktop.
Update EF Entity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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