Lately I have tried to learn NHibernate. NHibernate is a object-relational-mapper. It maps data from relational databases to POCO-objects. So, what is useful about that, you may ask? Well, for a starter, it’s very handy when creating a rich domain model. If you read this blog regularly, you may know that I’m also in the process of learning Domain Driven Design.
Domain Driven Design and NHibernate
The idea behind DDD is that you focus on the domain model instead of focusing on the database or GUI when trying to capture the business value from a domain expert. If you follow the guidelines described in the books written by gurus on the topic, you will end up with a domain model that is loosely coupled from the other parts of the system you are creating. That means you don’t have a coupling against the GUI, the database or any other parts of the system. But, you still need to persist the data from the domain model to the database in some way, and this is where NHibernate comes in to play. By setting up a mapping, described in a file, from the domain model to the database you can make NHibernate do the mapping for you. How cool is that? I guess you knew that already, but the purpose of this post is not to tell you how cool NHibernate is, but to guide you in the right direction of how to start learning NHibernate.
How I learned it
My first approach to learning NHibernate was to look at the excellent screen casts made by Stephen A. Bohlen called Summer of NHibernate. I learned a lot from watching these screen casts, but I still felt like something were missing. It’s like when you go to a conference, at the end of the day you can’t sit down in front of the PC and start to crank out code based on what you learn that day. But, it gives you a starting point. You often get information of how to investigate the topic further. This is what Summer of NHibernate did for me and it pointed me in the direction of a book called NHibernate in action.
Beside giving you a good start on setting up and using NHibernate, it also explains how to write real-world domain models. It tells you how to set up pretty complex associations between entities and why it’s important to understand why a domain model should be persistence ignorant and so on and so fourth. If you want to have a look at the index of the book, it can be found at this link.
If you want to learn NHibernate you definitely should look at this book.
Links to NHibernate resources I have used and use:
- Summer of NHibernate (screen casts)
- Dimecasts.org have some screen casts on the topic (max 10 minutes long)
- NHibernate in action (excellent book on the topic)
- NHibernate.org (You can download the binaries from this site and you find documentation)