Since a few years, NHibernate offers a code based mapping model. So you no longer need to create and maintain long and cumbersome XML files but instead you can create your mappings from code (and even apply some conventions if you want).
As I’m kind of used to the XML mapping, I find it useful to have a look at the XML for debugging purposes.
Here is the required code to generate the XML mappings from the ConfORM code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} | |