Geeks With Blogs
Keith Nicholas

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! 

Posted on Friday, April 30, 2010 11:37 AM | Back to top


Comments on this post: NHibernate 3.0 and FluentNHibernate, how to get up and running….

# re: NHibernate 3.0 and FluentNHibernate, how to get up and running….
Requesting Gravatar...
Try changing your VB.NET lambda to use `OrElse`. The VB.NET `Or` statement is not short-circuiting. If you use OrElse, you should get the same code as C# produces.
Left by mattmc3 on Oct 11, 2010 8:43 AM

# re: NHibernate 3.0 and FluentNHibernate, how to get up and running….
Requesting Gravatar...
Hi, thanks for the posting.

I've been doing pretty much the same thing, but my FluentNHibernate artifact won't load my ClassMaps anymore!

Can you please provide a link to your FluentNHibernate binaries compiled against NHibernate 3 Beta?
Left by Dave on Nov 11, 2010 10:05 PM

# re: NHibernate 3.0 and FluentNHibernate, how to get up and running….
Requesting Gravatar...
@mattmc3 That was my first thought as well! Closely followed by "VB has lambdas?"
Left by Leon Jollans on Dec 05, 2010 9:59 PM

# re: NHibernate 3.0 and FluentNHibernate, how to get up and running….
Requesting Gravatar...
Having just started using nHibernate, I gad to read all of the way to the end of that post to make sure you hadn't jumped ship.

That woulda made me wonder if I'd made the right call ;)
Left by James on Feb 03, 2012 12:21 AM

Your comment:
 (will show your gravatar)


Copyright © DesigningCode | Powered by: GeeksWithBlogs.net