Reviewed: NHibernate 2 Beginner's Guide
NHibernate 2 Beginner’s Guide by Aaron Cure is the 3rd published book about NHibernate. Each example in this book is presented in both C# and VB.NET, and some knowledge of these languages, as well as some basic understanding of ASP.NET WebForms is assumed.
Overall, for OR/M beginners and Entity Framework refugees, it provides a good foundation of NHibernate knowledge. The examples are simple enough to understand, and can easily be applied to real-world scenarios. There are, however, a few points of concern, such as the database-first approach, and the prescription of code generation.
Here’s a quick summary of what’s covered in each chapter:
As you might expect, chapter 1 gives a general overview of NHibernate, along with some code listings.
Chapter 2 sets up the database and table structure for the example model.
In chapter 3, the author takes us in to the world of POCO model design. He shows us NHibernate data types and their corresponding .NET data types, as well as setting up a collection for a one-to-many relationship.
In chapter 4, we begin the mapping process. After just a few pages, we have a completed NHibernate xml mapping. The chapter ends with a nice, quick example of a Fluent NHibernate code mapping. Chapter 4 is available for preview on the Packt Website.
In chapter 5, we start to get in to true NHibernate territory. The author shows us how to build a session factory, open a session, and then explains the proper use of transactions (Yes!). I would have preferred an example of session-per-request over the session provider singleton. Folks, save a kitten. Don’t use singletons.
Chapter 6 shows off all the log4net goodness baked in to NHibernate.
Chapter 7 explains the ins and outs of NHibernate configuration, with code and xml examples.
Chapter 8 shows us an example Data Access Object and how to build some Criteria queries with projections, paging, and sorting, It’s good stuff for beginners, but it doesn’t cover HQL.
In Chapter 9, the author shows us how to use NHibernate with ASP.NET WebForms data binding. No beginner’s book would be complete without showing the Microsoft way.
Chapter 10 deals with ASP.NET security and authorization, including a membership provider based on NHibernate.
Chapter 11 shows off several code generation tools. While this is the logical destination for anyone using a database-first approach, with a model-first approach, its unnecessary for all but the largest projects.
Disclosure: In exchange for non-monetary compensation, I worked as one of two technical reviewers on this book, and I am currently writing NHibernate 3 Cookbook, to be published by Packt later this year.