Skip to content

Instantly share code, notes, and snippets.

@randyburden
Created November 28, 2012 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randyburden/4164775 to your computer and use it in GitHub Desktop.
Save randyburden/4164775 to your computer and use it in GitHub Desktop.
NHibernate Duplicate Mapping Problem Solution
/*
NHibernate now has the BeforeBindMapping event which gives you access to the object representation of the HBM XML files at runtime.
Use the BeforeBindMapping event to gain access to the object representation of the .HBM XML files.
This event allows you to modify any properties at runtime before the NHibernate Session Factory is created. This also makes the FluentNHibernate-equivalent convention unnecessary. Unfortunately there is currently no official documentation around this really great feature.
Here's a global solution to duplicate mapping problems ( Just remember that all HQL queries will now need to use Fully Qualified Type names instead of just the class names ).
*/
var configuration = new NHibernate.Cfg.Configuration();
configuration.BeforeBindMapping += (sender, args) => args.Mapping.autoimport = false;
// The functional equivalent in Fluent NHibernate would be this:
.Mappings(
m =>
{
m.FluentMappings.Conventions.Setup( x => x.Add( AutoImport.Never() ) );
} )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment