Introduction to Fluent Nhibernate

Introduction to Fluent Nhibernate

05 Apr 2024
2 min read
Learn via Video Course & by Doing Hands-on Labs

Self-Paced ASP.NET Core Course

Fluent Nhibernate is a great O/RM tool to specify strongly typed mapping in the form of classes on the top of NHibernate framework. Fluent Nhibernate offers a simplified implementation of Nhibernate without using the XML(hbm) mapping files. Fluent NHibernate lets you write mappings in strongly typed C# code. Also, you can learn our previous article about entity framework

Fluent nhibernate also provides the option for you to do an automapping where the mapping is automaticaly created and managed by fluent nhibernate. Creating Fluent Nhibernate automapping is pretty much straight forward in OneToOne, OneTomany relationship, but when it comes to ManyToMany relationship it is not easy.

Nhibernate Configuration files issues

The most important complains I personally have on NHibernate configuration files are:

  1. It is error prone.

  2. Errors in configuration file can be hard to trace.

  3. It is not refactoring friendly.

Fluent NHibernate Tools

  1. Auto mapping

    Fluent NHibernate automatically mapping all your entities based on a set of conventions.By using the auto mappings, you can map your entire domain with very little code, and certainly no XML.

  2. Persistence specification testing

    It provides a round-trip testing for your entities, without ever having to write a line of code. You can quickly test your mappings using the PersistenceSpecification class.

  3. Fluent configuration

    Fluent NHibernate provides an API to configure NHibernate for use with your application

  4. Database configuration

    Fluent NHibernate provides an API for configuring your database, this can be used in combination with the fluent configuration or on it's own.

Installing Fluent NHibernate

Fluent NHibernate is an open source project (OSS). Thus, the code and/or the binaries are freely available and can be downloaded from Github. Before you can start coding, you must first download Fluent NHibernate libraries that can be found here: .Unzip downloaded file and extract it into a folder of your choice.

Now start Visual Studio and create new web application project. Now you need to add references of Fluent NHibernate dll to your project. Right click on the References in your solution explorer and select Add Reference. Now browse the directory where you have extracted your Fluent NHibernate libraries and reference the following dll files:

  1. FluentNhibernate.dll

  2. NHibernate.dll

  3. NHibernate.ByteCode.Castle

Now you can continue to work on your web application with fluent nhibernate mapping to the database using strongly typed C# classes.

Share Article

Live Classes Schedule

Our learn-by-building-project method enables you to build practical/coding experience that sticks. 95% of our learners say they have confidence and remember more when they learn by building real world projects.
Software Architecture and Design Training Jul 28 SAT, SUN
Filling Fast
05:30PM to 07:30PM (IST)
Get Details
Azure Developer Certification Training Jul 28 SAT, SUN
Filling Fast
10:00AM to 12:00PM (IST)
Get Details
ASP.NET Core Certification Training Jul 28 SAT, SUN
Filling Fast
07:00AM to 09:00AM (IST)
Get Details
ASP.NET Core Project Aug 24 SAT, SUN
Filling Fast
07:00AM to 09:00AM (IST)
Get Details

Can't find convenient schedule? Let us know

About Author
Shailendra Chauhan (Microsoft MVP, Founder & CEO at Scholarhat by DotNetTricks)

Shailendra Chauhan is the Founder and CEO at ScholarHat by DotNetTricks which is a brand when it comes to e-Learning. He provides training and consultation over an array of technologies like Cloud, .NET, Angular, React, Node, Microservices, Containers and Mobile Apps development. He has been awarded Microsoft MVP 8th time in a row (2016-2023). He has changed many lives with his writings and unique training programs. He has a number of most sought-after books to his name which has helped job aspirants in cracking tough interviews with ease.
Accept cookies & close this