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.
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:
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.
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 user need this very complex GUI. The user-story is as follows:
This is all for now, in the next post I will talk about the architecture that I will use.