Configuring Fluent NHibernate with an External NHibernate Config File

A while ago I was having issues using configuring fluent NHibernate with an external configuration file. I kept running into the issue of mappings not being registered. I was finally able to get it working appropriately and thought I would share my solution. The key is to configure the normal mappings first and then pass that configuration in when configuring fluent NHibernate.

string configFile = "hibernate.cfg.xml";

//setup the normal map configurationConfiguration normalConfig = new Configuration().Configure(configFile);

//setup the fluent map configurationFluently.Configure(normalConfig)	.Mappings(		m => m.FluentMappings		.ConventionDiscovery.Add(DefaultLazy.AlwaysFalse())		.AddFromAssemblyOf<UserMap>())	.BuildConfiguration();

About Sean Biefeld

Hello all, my name is Sean Biefeld. I graduated from Baylor University with a BBA in Management Information Systems. I am currently working for McLane Advanced Technologies . The opinions expressed by me, however accurate they may be, are not necessarily those of my employer. I have been a developing software professionally since 2004. My primary development focus is on HTML, CSS, JavaScript and C#. I dabble in a little PHP and Ruby. This blog is a forum for me to post my experiences, ideas, rants, and thoughts as I traverse the mountain of life.
This entry was posted in configuration, Fluent NHibernate, infrastructure, Nhibernate. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • http://www.fullmobile.com/ Car Market

    perfect, this is what I was looking for a long time … you saved my day by sharing …

  • http://olwyolgomyck.com/ lgnhyhvp

    ZblbkM yderaxajfxdf, [url=http://nrqbaxbbuycx.com/]nrqbaxbbuycx[/url], [link=http://hjmagpdqleta.com/]hjmagpdqleta[/link], http://lmyoytgrecag.com/

  • Matt

    Thanks a lot!