I'm trying to have a deepcopy of an entity record so that I can compare it at a later time.
I've tried multiple DeepCopy Codes but they are producing this error.
var oldAddress = DeepClone(_entity.Addresses.Where(x => x.Id ==
addressDTO.Id).FirstOrDefault());
"System.Data.Entity.DynamicProxies.....is not marked as serializable."
Code used
public static T DeepClone<T>(this T obj)
{
using (var ms = new MemoryStream()) {
var bf = new BinaryFormatter();
bf.Serialize(ms, obj);
ms.Position = 0;
return (T)bf.Deserialize(ms);
}
}