The object-relational mapper for .NET

Introducing NHiberate and WPF: The ChinookMediaManager

As you can note in my previous posts I’ve talked a lot about NHibernate and WPF. So I've decided to write an ongoing series of blog posts about the integration of these two technologies.


The motivation behind this series of posts is very simple most of the articles that you can read about NHibernate are for web technologies such as ASP.Net or ASP.NET MVC. Despite the fact that NHibernate is an ORM and has nothing to do with the presentation layer there are certain consideration that you have to take into account to build a good architecture.

Sample Domain

For this series of post I have chosen to use a small subset of the Chinook database with few modifications. I have changed all the Identities primary keys to HiLo. You can find both the original and the slightly modified version here (with class, mappings and read only tests).

This is the full database schema:

However we will focus in this subset of the domain:



A word about session management

Most of the examples of NHibernate for web applications uses a pattern called “Session-per-Request”, this means that the session and the transaction has the same lifetime that the web request. This pattern is very easy to work with and very easy to understood but is not suitable for desktop applications.
There are two antipatterns called “session-per-application” and “session-per-call” that you need to avoid.
The pattern that I will use for this series is called “conversation per bussines transactions” and is very well described by his inventor Fabio Maulo. I’ve learned a lot with Fabio and Gustavo Ringel  about CpBT.

A word about data binding

In this series of post we will make intensive use of WPF data binding capabilities. Is for that reason that I’ve written uNHAddIns.WPF that uses NHibernate extensions points to bring us few behaviors that we need for data binding.

The interface that we have to solve


The user need this very complex GUI. The user-story is as follows:

  • The user can have multiple instances of this window open for editing albums of different artists.
  • The user can add albums.
  • The user can add tracks to the new albums and preexistent albums.
  • None of the information is persisted until the user press “Save All”.
  • If the user press close the application will ask to the user if he really want to discard all changes.

This is all for now, in the next post I will talk about the architecture that I will use.

Posted Sun, 16 August 2009 12:26:25 AM by jfromainello
Filed under: Session WPF

comments powered by Disqus
© NHibernate Community 2017