Saturday, January 9, 2010

NHibernate – Architecture (Part 2)

NHibernate’s programming interfaces are mainly classified into 4 sections.

  • Core Interfaces – The applications interact with NHibernate using these interfaces to perform operations on the DB. These interfaces are the main point of dependency between the application and NHibernate. E.g.  ISession, ITransaction, IQuery etc.
  • Configuration interfaces – These interfaces are used by the applications to configure NHibernate. 
  • Callback interfaces – Allows applications to react to NHibernate events
  • Mapping interfaces - Interfaces that allow extension of NHibernate’s powerful mapping functionality



As you can see from the diagram, the configuration object is used to configure NHibernate. The application uses a Configuration instance to specify the location of mapping documents and to set NHibernate-specific properties before creating the ISessionFactory.
Once the session factory is created, we can use the instance to create an ISession object. The ISession object is the primary interface used by NHibernate applications. It exposes NHibernate’s methods for finding, saving, updating, and deleting objects.
The IQuery and ICriteria interfaces give you powerful ways to perform queries against the database while also controlling how the query is executed. These interfaces are used for fetching data using NHibernate. In the samples used in this blog, we'll be using Linq to NHibernate which is a layer build on top of these interfaces.
Apart from these another NHibernate interface we are interested is the Type. A NHibernate Type object maps a .NET type to a database column type. All persistent properties of persistent classes, including associations, have a corresponding NHibernate type. This design makes NHibernate extremely flexible and extensible because each RDBMS has a different set of mapping to .NET types. In the upcoming posts we’ll see how to use these interfaces to unleash the power of NHibernate and work on the data.

No comments: