Chapter 1: Introduction to FluentNHibernate

After working over 2 years with FluentNHibernate, I have now decided I should write a step by step learning schedule for Fluent NHibernate. The reason? … Well lets just say it’s better to wait for it. Once you learn FluentNHibernate, I guess, you will never go back to your old SQL query based development, trust me, you won’t.

When I learned FluentNH, it took me a while to find solutions, as help was not that much available all the time.

But I must be glad to those extraordinary people at stackoverflow ( ) who helped me find solutions to problems and also helped me learn FluentNH.

This is an approach of mine, to bring all those thoughts and solutions in one place, so that you can find all without going under the hassle that I went through.

Before beginning with FluentNHibernate, I would like to introduce you with it a bit.

For those, who have worked with FluentNH earlier, you can skip the next section.

FluentNH is an ORM in long Object Relation(al) Mapper. Now, the big question is, What is a ORM? well keep reading….

  1. What is a ORM?
    In simple words, I would say ORM is an advanced technique which is actually originated from OOP ( Object Oriented Programming) concept and is created on the sole purpose to provide developers like us, the capability to perform persistent store management, such as managing a database, with a complete OOP approach.Confused? Okay lets see an example of what I meant. Consider  a very simple case -” Suppose you have 1 table in database name “User” with 2 fields in it username and password.Now, lets say we have to create a single user to the database, what will be a our approach? Okay, lets say we are creating a huge ERP solution, and thus we will use the 3-tier architecture. So we have Presentation Layer, Business Logic and Data Access Components. No matter what we use, somewhere in the DataAccess layer we will need to create a SQL connection and generate a query of some thing like –Select * From <Table> Where <Condition> Order By <field>This is just for one single table and running a query from it. Think about the whole database with hundreds of tables. Well, its better not to think about it, you know what I am talking about. This is where a ORM kicks in.A ORM is the abstraction layer, that gives you the opportunity to run queries just like normal codes in C#. For example in one of your codes you might use something like this –Person p = Repository.Get<Person>(“Id”, <someid>);

    Thats right, no more sql queries and no more table adapters and no more data sets. That singe line will do the rest.

    If you use a ORM you don’t have to type all the sql codes by hand. You create a nice simple repository class and let the ORM handle the test. And frankly speaking, until I knew about ADO.Entity Framework (v3), I never thought any library or ORM will be able to compete with FluentNH.

I think, thats enough for you to just give you a very rough idea of what is a ORM. But until you use it in your projects, I guess it won’t be of much help.

Stay tuned for the next articles on FluentNH.