Generic Clone of EF6 Entity

后端 未结 3 1969
没有蜡笔的小新
没有蜡笔的小新 2021-01-27 11:16

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         


        
3条回答
  •  灰色年华
    2021-01-27 11:31

    I think they give you one out of the box. Try something like:

    context.Entry(MyNewEntity).CurrentValues.SetValues(MyOldEntity);
    

提交回复
热议问题