I am trying to get a generic CloneEntity function working with EF6.0.2
public static T CopyEntity(MyContext ctx, T entity,
bool copyKeys = false) where
public class EntityHelper
{
public static T CopyEntity(MCEntities ctx, T entity, bool copyKeys = false) where T : class, new()
{
T clone = new T();
var en = ctx.Entry(clone);
en.State = System.Data.Entity.EntityState.Added;
ctx.Entry(clone).CurrentValues.SetValues(entity);
en.State = System.Data.Entity.EntityState.Detached;
return clone;
}
}