Nhibernate HbmMapping to Xml

I use NHibernate mapping by code to map classes.

Sometimes, in order to debug my NHibernate configuration, I would need to check exactly what parameters were passed to NHibernate, and it is quite difficult to debug the display by code.

Is there a way to convert the generated HbmMapping back to an Xml file, as if it were manually entered?

This will help in diagnosing the problem that underlies my comparisons!

+3
source share
1 answer

Option 1

We’ll warn you that this will write the XML to your BIN folder, causing the IIS pool to recycle, so run it once, and then comment out the line WriteAllXmlMapping!

var mapper = new ModelMapper();
mapper.AddMappings(typeof(CmsMeta).Assembly.GetTypes());

//This will write all the XML into the bin/mappings folder
mapper.CompileMappingForEachExplicitlyAddedEntity().WriteAllXmlMapping();

Option 2

XML , .

var mapper = new ModelMapper();
mapper.AddMappings(typeof(CmsMeta).Assembly.GetTypes());
var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();

//you could add a breakpoint here! 
var mappingXml = mapping.AsString();

, .

+6

All Articles