How to check your Fluent mapping against HBM mapping when using Fluent NHibernate?

Recently I was tasked with converting an existing application’s NHibernate mappings to Fluent NHibernate. The original mappings were done as XML-based hbm files. Bottom line is that there was nothing wrong with the hbm mappings, and one is able to mix-and-match hbm mappings with fluent mappings, but for the purposes of the project we decided is preferable to settle on one standard.

One particular mapping proved to be a bit challenging to convert. The hbm XML file contained the following map:


<bag name="Features" access="field.camelcase-underscore" cascade="all" lazy="true" table="WebsiteFeatures">
 <cache usage="read-write"/>
 <key column="WebsiteID"/>
 <element column="Feature" type="Model.Types.FeatureType, Model" not-null="true"/>
</bag>

After creating the fluent map, I wanted to check that I was a close to the original hbm mapping as possible. To do this is actually quite simple. Just configure your Fluent configuration to export its mappings to file, like so:


return Fluently.Configure()
  .Database(MsSqlConfiguration.MsSql2008
  .ConnectionString(x => x.FromConnectionStringWithKey("DefaultConnection"))
  .Mappings(x => x.FluentMappings.AddFromAssemblyOf ().ExportTo(@"C:\BloggingTemp\"))
  .BuildConfiguration();

The XML mappings are then exported to your selected directory and you’re able to compare them against your original hbm maps.

Advertisements
Explore posts in the same categories: Development, NHibernate

Tags: ,

You can comment below, or link to this permanent URL from your own site.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: