I am trying to customize the DatabaseAuditor. One of the things I need to do is to write the complete entity XML to a database field for deletes and updates.
I'm stuck on the method to clone the entity and extract the XML from the clone. I keep getting an ORMEntityOutOfSyncException.
I've tried this code
private string GetEntityXML(IEntityCore entity)
{
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
formatter.Serialize(stream, entity);
// seek the stream back to the beginning.
stream.Seek(0, SeekOrigin.Begin);
// deserialize the data back into a new instance (and all the related entities)
IEntityCore clone = (IEntityCore)formatter.Deserialize(stream);
string xml = string.Empty;
clone.WriteXml(out xml);
return xml;
}
What am I doing wrong?