Derik Whittaker

Syndication

News


Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Using Fluent-NHibernate and Traditional .hbm.xml files in the same project

The key goal to the Fluent-NHibernate project is to allow you to remove yourself from creating .hbm files.  However, there are many scenarios where having both may make sense (say in a legacy situation).

Because I ran into the need to include a single .hbm file in my solution I thought would share the wealth.

Now if you are familiar with NHibernate you know that in order to use the .hbm files you need to do a few things.

  1. Give the mapping file the extension .hbm.xml
  2. Set the build action to ‘Embedded Resource’
  3. Set the copy-to-output to ‘Copy Always’

If you are like my project and you have not setup your configuration to pull any .hbm files from disk you will need to make a small tweak to do so.  You will need to go your spot in code where you have setup your configuration object for NHibernate and add the following line.

// configuration is an instance of Configuration
// my .hbm files output to a Mappings dir when i build
configuration.AddXmlFile( "Mappings/Insurance.hbm.xml" );

By adding this line you can tell NHibernate to use your mappings file or your FluentMappings setup.

Hope this helps,

Till next time,


Posted 01-28-2009 3:22 PM by Derik Whittaker

[Advertisement]

Comments

DotNetShoutout wrote Using Fluent-NHibernate and Traditional .hbm.xml files in the same project
on 01-29-2009 6:33 AM

Thank you for submitting this cool story - Trackback from DotNetShoutout

Ben Scheirman wrote re: Using Fluent-NHibernate and Traditional .hbm.xml files in the same project
on 01-29-2009 11:20 AM

btw, the only reason you'd need to mark the mapping as embedded resource is if you do

configuration.AddAssembly(...);  this will scan the assembly for embedded resources named *.hbm.xml.

If instead you want to load the mapping file (as you've done, then you need to copy to output directory.  The two settings are mutually exclusive.

Hope that helps.

Dew Drop – January 29, 2009 | Alvin Ashcraft's Morning Dew wrote Dew Drop – January 29, 2009 | Alvin Ashcraft's Morning Dew
on 01-29-2009 11:32 AM

Pingback from  Dew Drop – January 29, 2009 | Alvin Ashcraft's Morning Dew

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)