Skip to content

Instantly share code, notes, and snippets.

@wullemsb
Created February 9, 2014 19:54
Show Gist options
  • Save wullemsb/8905001 to your computer and use it in GitHub Desktop.
Save wullemsb/8905001 to your computer and use it in GitHub Desktop.
Generate nHibernate XML mapping
var mapper = new ModelMapper();
/*Add your ConFORM mapping code here*/
var compiledMappings = mapper.CompileMappingForEachExplicitlyAddedEntity();
var setting = new XmlWriterSettings { Indent = true };
var serializer = new XmlSerializer(typeof(HbmMapping));
foreach (var hbmMapping in compiledMappings)
{
using (var memStream = new MemoryStream(2048))
using (var xmlWriter = XmlWriter.Create(memStream, setting))
{
serializer.Serialize(xmlWriter, hbmElement);
memStream.Flush();
memStream.Position = 0;
using (var sr = new StreamReader(memStream))
{
return sr.ReadToEnd();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment