Hi. I´m trying to use the NHibernate.Mapping.Attributes in order to auto generate the hbm.xml files instead of writing them by hand. By reading the examples I understand that I need to tell nHibernate to do it after I decorate the classes/properties. My HibernateHttpModule which was taken by this tutorial:
http://www.theserverside.net/tt/article ... NHibernate.
The solution is designed with the 3tiers and the DAL are accessed through the use of a Facade Pattern, meaning that the classes that should be dynamically mapped are in the BOL tier and the HibernateHttpModule is in the DAL tier, so if I use the following code in the HibernateHttpModule.cs :
Code:
// Use NHibernate.Mapping.Attributes to create information about our entities
System.IO.MemoryStream stream = new System.IO.MemoryStream(); // Where the information will be written in
NHibernate.Mapping.Attributes.HbmSerializer.Default.Validate = true; // Enable validation (optional)
// Ask to NHibernate to use fields instead of properties
NHibernate.Mapping.Attributes.HbmSerializer.Default.HbmDefaultAccess = "field.camelcase-underscore";
// Gather information from this assembly (can also be done class by class)
NHibernate.Mapping.Attributes.HbmSerializer.Default.Serialize( stream, System.Reflection.Assembly.GetExecutingAssembly() );
stream.Position = 0;
config.AddInputStream( stream ); // Send the Mapping information to NHibernate Configuration
stream.Close();
Then System.Reflection.Assembly.GetExecutingAssembly() will refer to the ExecutingAssembly which is DAL, thus there will be NO classes to map since they are in the BOL assembly ... should I map the classes 1 by 1, like:
Code:
System.IO.MemoryStream stream = new System.IO.MemoryStream(); // Where the information will be written in
NHibernate.Mapping.Attributes.HbmSerializer.Default.Validate = true; // Enable validation (optional)
// Ask to NHibernate to use fields instead of properties
NHibernate.Mapping.Attributes.HbmSerializer.Default.HbmDefaultAccess = "field.camelcase-underscore";
// Gather information from this assembly (can also be done class by class)
NHibernate.Mapping.Attributes.HbmSerializer.Default.Serialize( stream, System.Reflection.Assembly.GetAssembly( typeof( BOL.Class1) ) );
stream.Position = 0;
NHibernate.Mapping.Attributes.HbmSerializer.Default.Serialize( stream, System.Reflection.Assembly.GetAssembly( typeof( BOL.Class2) ) );
stream.Position = 0;
oConfig.AddInputStream( stream ); // Send the Mapping information to NHibernate Configuration
stream.Close();