Hello all,
I have this extension method for cloning my LINQ To SQL objects:
public static T CloneObjectGraph<T>(this T obj) where T : class
{
var serializer = new DataContractSerializer(typeof(T), null, int.MaxValue, false, true, null);
using (var ms = new System.IO.MemoryStream())
{
serializer.WriteObject(ms, obj);
ms.Position = 0;
return (T)serializer.ReadObject(ms);
}
}
But while i carry objects with not all references loaded, while qyuerying with DataLoadOptions, sometimes it throws the object disposed exception, but thing is I don't ask for references that is not loaded (null).
e.g. I have Customer with many references and i just need to carry on memory the Address reference EntityRef<> and i don't Load anything else. But while i clone the object this exception forces me to load all the EntitySet<> references with the Customer object, which might be too much and slow down the application speed.
Any suggestions?