NHibernate 3.0 and FluentNHibernate, how to get up and running….

Posted by DesigningCode on Geeks with Blogs See other posts from Geeks with Blogs or by DesigningCode
Published on Thu, 29 Apr 2010 22:37:54 GMT Indexed on 2010/04/29 23:58 UTC
Read the original article Hit count: 372

Filed under:

First up. Its actually really easy.

I’m not very religious about my DB tech, I don’t really care, I just want something that works.  So I’m happy to consider all options if they provide an advantage, and recently I was considering jumping from NHibernate to EF 4.0.  However before ditching NHibernate and jumping to EF 4.0 I thought I should try the head version of NHibernates trunk and the Head version of FluentNHibernate.

I currently have a “Repository / Unit of Work” Framework built up around these two techs.  All up it makes my life pretty simple for dealing with databases.   The problem is the current release of NHibernate + the Linq provider wasn’t too hot for our purposes.  Especially trying to plug it into older VB.NET code.   The Linq provider spat the dummy with VB.NET lambdas.  Mainly because in C#

Query().Where(l => l.Name.Contains("x") || l.Name.Contains("y")).ToList();

is not the same as the VB.NET

Query().Where(Function(l) l.Name.Contains("x") Or l.Name.Contains("y")).ToList

VB.NET seems to spit out … well…. something different :-)

so anyways… Compiling your own version of NHibernate and FluentNHibernate.  It’s actually pretty easy!

First you’ll need to install tortisesvn NAnt and Git if you don’t already have them. 

NHibernate

first step, get the subversion trunk

https://nhibernate.svn.sourceforge.net/svnroot/nhibernate/trunk/

into a directory somewhere.  eg \thirdparty\nhibernate

Then use NAnt to build it.   (if you open the .sln it will show errors in that  AssemblyInfo.cs doesn’t exist )

to build it, there is a .txt document with sample command line build instructions,  I simply used :-

NAnt -D:project.config=release clean build >output-release-build.log

*wait* *wait* *wait* and ta da, you will have a bin directory with all the release dlls.

FluentNHibernate

This was pretty simple.

there’s instructions here :- http://wiki.fluentnhibernate.org/Getting_started#Installation

basically, with git, create a directory, and you issue the command

git clone git://github.com/jagregory/fluent-nhibernate.git

and wait, and soon enough you have the source.

Now, from the bin directory that NHibernate spit out, take everything and dump it into the subdirectory “fluent-nhibernate\tools\NHibernate”

Now, to build, you can use rake….which a ruby build system, however you can also just open the solution and build.   Which is what I did.  I had a few problems with the references which I simply re-added using the new ones. 

Once built, I just took all the NHibnerate dlls, and the fluent ones and replaced my existing NHibernate / Fluent and killed off the old linq project.

All I had to change is the places that used  .Linq<T>  and replace them with .Query<T>  (which was easy as I had wrapped it already to isolate my code from such changes)

and hey presto, everything worked.  Even the VB.NET linq calls.

I need to do some more testing as I’ve only done basic smoke tests, but its all looking pretty good, so for now, I will stick to NHibernate! 

© Geeks with Blogs or respective owner