concept NHibernate in category asp.net

This is an excerpt from Manning's book ASP.NET MVC 2 in Action.
If you’re familiar with NHibernate (http://nhibernate.org), you may be familiar with the Session-per-Request pattern. It refers to the lifecycle of the NHibernate Session object—in web environments it’s common to open the session at the beginning of the request and close it at the end. Throughout the request, the current session is available in HttpContext.Items. There’s an example of this in chapter 23.
To achieve separation of concerns when communicating with a relational database, we can use an object-relational mapping tool such as the popular open source NHibernate project. NHibernate makes data access with relational databases trivial. As with anything new, a learning curve is associated with understanding the method of configuring the mapping between objects and tables. This chapter demonstrates how to configure and leverage NHibernate when developing an application whose UI takes advantage of the ASP.NET MVC Framework. This example is equally applicable in ASP.NET MVC 1 and 2.
There’s little code to write in order to leverage NHibernate for seamless persistence. NHibernate is a library, not a framework, and the difference is important. Frameworks provide templates of code, and we then fill in the gaps to create something useful. Libraries are usable without providing templates. NHibernate doesn’t require our entities to derive from a specific base class or the implementation of a specific interface. NHibernate can persist any type of object as long as the configuration is correct.
In this section, we’ll walk through the configuration of NHibernate and see how we can save and retrieve the Visitor object. For this chapter, we’re using NHibernate 2.1 with Fluent NHibernate 1.0 for configuration help. Fluent NHibernate provides XML-less, compile-safe, automated, convention-based mappings for NHibernate. You can find it at http://fluentnhibernate.org/.
Before we dive into the configuration, let’s examine the implementation of the IVisitorRepository interface specified in the domain model. We’ll start with this class to demonstrate how little code is written when calling NHibernate to perform a persistence operation. Listing 23.4 shows the VisitorRepository class located in the Infrastructure project.