Review - NHibernate 2 - Beginner's Guide From PACKT Publishing


Programming in Ruby tutorials and examples

Review - NHibernate 2 - Beginner's Guide From PACKT Publishing

MaxCDN Content Delivery Network

I was contacted by PACKT publishing about a month ago and they asked me to review the NHibernate 2 Beginners guide.

The book assumes that the reader has some knowledge of the .NET framework and either C# or VB.Net.

If you are completely new to NHibernate then this book is a great starting point enabling new-bee’s to get up and running very quickly. I would have to say that if you have experience using NHibernate then this book will not be for you, as it lack’s some of the more advanced concepts and information needed. But as this is a book for beginner’s lets put that opinion to one side.

Firstly the book starts off by introducing NHibernate and ORM’s in general explaining what NHibernate is and also it’s benefits.

Basic database design concepts are then covered demonstrating how to create tables and relationships and then use classes to represent your data. Both Xml and Fluent Nhibernate mapping is covered with examples of how to map o2m, m2m and m2o relationships from your database to your domain model.

The author then goes onto explain the usage of the NHibernate Session and how to plumb in logging using log4net. After some “Have a go hero” tasks where the author encourages the reader to create some simple examples the book swiftly moves on to configuration.

Examples of how to configure NHibernate programmatically and also using XML are explained including the different proxy options for lazy loading.

Unfortunately I felt the chapter on querying does not do enough to explain the difference between eager and lazy loading. Also I felt that the use of constant variables to hold strings relating to field names in order to gain strongly typed query’s could have been demonstrated differently. Either Linq2NHibernate or the Nhibernate Lambda Extensions framework would have been a better choice. Basic CRUD (Create, Read, Update and Delete) operations are explained fully with examples.

By far my most favourite chapter in the book was on code generation and even as an NHibernate veteran I really learned a lot. I used to hate code-gen before I read this book, my new favourite code-gen tool is MyGeneration with a customised L99 template – happy days!

All in all I feel that if you are looking to learn NHibernate then there is no better starting place than the NHibernate 2 Beginner’s Guide.

NHibernate 2 - Beginner’s Guide