entity framework 6 - c# comparing objects without creating dto -


currently creating dto of object compare new , old values. fine when 1 object, in future that's going change. tried creating extension method serialize , deserialize deep copy, postsharp throwing error.

type 'postsharp.patterns.model.notifypropertychanged.changetracking.childpropertychangedprocessor' in assembly 'postsharp.patterns.model, version=4.2.28.0, culture=neutral, publickeytoken=e7f631e6ce13f078' not marked serializable. (serializationexception)

here extension method , error being thrown @ formatter.serialize(stream, source).

public static t clone<t>(this t source) {     if (!typeof(t).isserializable)     {         return default(t);     }      if (referenceequals(source, null))     {         return default(t);     }      var formatter = new binaryformatter();     stream stream = new memorystream();     using (stream)     {         formatter.serialize(stream, source);         stream.seek(0, seekorigin.begin);         return (t) formatter.deserialize(stream);     } } 

is there way fix error or have way? if have find way approach should take?

you use automapper well: (every app should use anyway, what's harm?)

var clone = new poco(); mapper.createmap<poco, poco>(); mapper.map<poco, poco>(source, clone); 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -