I have found a nice solution in the internet which mets our requirements. We clone our object graphs by serialization. The code in our BaseModel class is the following:
Code:
/// <summary>
/// Clones the object by using serialization and deserialization.
/// </summary>
/// <returns>
/// A deep copy of the object.
/// </returns>
private object cloneBySerialization()
{
Object result;
MemoryStream buffer = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(buffer, this);
buffer.Position = 0;
result = formatter.Deserialize(buffer);
return result;
}
As we don't use lazy collections (because of the specific requirements in our application) this works fine for us.
Regards
Klaus