How to Use Fluent Nhibernate, LINQ and SQLite in ASP.NET MVC 3 Project?

November 20, 2010 · 2 comments

in ASP.NET MVC,Fluent NHibernate,LINQ,NHibernate

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.

  1. 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.

  2. 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.

  3. 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-nhibernate\src\FluentNHibernate\ to 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.
  4. 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.

  5. 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.

Download or Browse the sample project here.

  • http://www.jonathanchannon.com Jon

    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

    thanks Now i just plan to crate my own site.This will help me.

Previous post:

Next post: