Here are the steps I followed to use LINQ with Fluent NHibernate, nHibernate 3.0 in an ASP.NET MVC 3 project. This article includes a very simple ASP.NET MVC 3 blog
application. The application is mostly limited to listing, creating, updating and viewing details of a Post entity.
-
Create a New MVC3 project.First download and install MVC3 RC [ASP.NET MVC 3 RC].
ASP.NET MVC 3 can be installed side by side with ASP.NET MVC2 so MVC 2 doesn’t need to be uninstalled for v3 to run.
After installing v 3.0 create a new ASP.NET MVC 3 project. For this tutorial I will be using the Razor View Engine. -
Download Nhibernate 3.0.Since we don’t need the full source code for NHibernate 3, we can just download the binaries for NHibernate v3.
Download NHibernate 3 here. -
Setup Fluent Nhibernate to Use LINQ.As of this writing, Fluent Nhibernate has a dependency on Nhibernate 2 which doesn’t support LINQ. In order to use LINQ along with Fluent Nhibernate we
need to build Fluent Hibernate source with Nhibernate v3. First get the source for fluent Nhibernate hosted in github.
To get the source you will need to have git installed in your system. Run the following command to get the latest Fluent Nhibernate source -
assuming git is in your PATH.
git clone git://github.com/jagregory/fluent-nhibernate.git fluent-nhibernate
Add the Fluent Nhibernate VS.NET project located in [Path]fluent-nhibernatesrcFluentNHibernateto your ASP.NET MVC 3 project. - Convert the Fluent Nhibernate project to target .NET 4
- Remove all Nhibernate 2.0 library references from Fluent NHibernate project. In particular you might be interested in the follwoing libraries -
NHibernate, Iesi.Collections, Antlr3.Runtime. - Add the NHibernate v3 libraries – all libraries removed in earlier step – to the project and build it.
-
Use NHibernate 3 LINQ. NHibernate defines the LINQ specific functionalities in
NHibernate.Linq. Here is a sample code that shows how to use LINQ in NHibernate. -
Use SQLite
In order to use SQLite in our project, download the .NET driver from here.
Reference the Dlls from your ASP.NET MVC 3 project.
Jon January 10, 2011 at 7:08 pm
Thanks for this!
I just started using NHibernate & Fluent and was banging my head where the LINQ stuff was. I was missing the using NHibernate.Linq;
Mani February 15, 2012 at 9:06 am
thanks
Now i just plan to crate my own site.This will help me.