Jun 04 2009

Book review: NHibernate in Action

Category: Uncategorizedbengtbe @ 19:39

NHibernate In Action

Authors: Pierre Henri Kuaté, Tobin Harris, Christian Bauer, and Gavin King
Publisher: Manning Publications Co.
Manning, Amazon.com, Amazon.co.uk


As part of my goal to learn ORM and NHibernate I purchased the NHibernate in Action book from Manning Publications.
Before I give my conclusion, let’s start with a summary of the different chapters in the book.

1. Object/relation persistence in .NET

This chapter starts the first part of the book, called Discovering ORM with NHibernate. Discusses object persistence, and briefly compares different approaches: hand coding, DataSets, LINQ-to-SQL, NHibernate, and ADO.NET Entity Framework. Describes Object/Relational mapping (ORM), and how it is used to solve the Object/Relational mismatch.

2. Hello NHibernate

Guides you through the process of setting up a project, creating a domain model, setting up the database, creating mapping file, configuring NHibernate, and doing some basic CRUD operations. Takes a high level look at NHibernate, its architecture and how it is configured.

3. Writing and mapping classes

This chapter starts the second part of the book, called NHibernate deep dive. Describes the most common scenarios when mapping a domain model to the database, including important concepts, such as object identity, inheritance, associations, entities vs. value-types, fine-grained object models, and transparent persistence. Finally, it shows three inheritance mapping strategies; table per concrete class, table per class hierarchy, and table per subclass. Covers both XML-mapping and attribute mapping.

4. Working with persistent objects

Describes the three object states (persistent, detached, and transient) that domain models have in a NHibernate application, and how they move from one state to another. It also gives an overview of different ways to get objects out of the database.

5. Transactions, concurrency, and caching

Shows how NHibernate handles transactions, short vs. long conversations, optimistic concurrency control and versioning. Finally it discusses caching and describes the first- and second-level cache that NHibernate provides.

6. Advanced mapping concepts

Goes into detail of more advanced mapping techniques, covering mapping types, custom mapping types, nullable types, enumerated types, collection of value types, mapping of entity associations, and mapping of polymorphic associations.

7. Retrieving objects efficiently

Describes object retrieval with both HQL, Query by Criteria, and native SQL. Topics covered are parameters, comparison operators, logical operators, ordering, joining, report queries, dynamic queries, and query optimization.

8. Developing NHibernate applications

This chapter starts the last part of the book, called NHibernate in the real world. Discusses N-tier development by going through the business, persistence, and presentation layer. Finally it shows how NHibernate can be used to implement audit logging.

9. Writing real-world domain models

Covers domain-model development processes and tools, legacy schema mapping, understanding persistence ignorance, implementing business logic, data binding entities in the GUI, and filling DataSets from entities.

10. Architectural patterns for persistence

Focuses on the design of the persistence layer. Covers designing the persistence layer, implementing reusable Data Access Objects, implementing conversations, and using NHibernate in an Enterprise Services application.


First let’s start with the things that I like about the book. As far as I know it is the only book published about NHibernate, and great OR/M deserves its own book. The book is well written and structured. It covers many aspects of NHibernate, and gives you enough information to start using NHibernate in your own project. The first part of the book is great for beginners of NHibernate. The second part covers more advanced topics and people with some experience with NHibernate should also find something useful in these chapters.

Unfortunately, there are some things that I don’t like about the book. It covers NHibernate 1.2, even though 2.0 was released when the book came out. I also think that the last part of the book covers to much basic stuff about Domain Driven Design and N-tier development, instead of focusing on how to utilize NHibernate. Hopefully, the authors will release a second edition that covers version 2+, and also covers more community project, like Fluent NHibernate.

Overall I give this book 3.5 of 5 stars :)

kick it on DotNetKicks.com Shout it

Tags: ,

Mar 09 2009

Book review: Microsoft .NET: Architecting Applications for the Enterprise

Category: Uncategorizedbengtbe @ 08:17

Authors: Dino Esposito & Andrea Saltarello
Publisher: Microsoft Press
Purchase: Amazon.com, Amazon.co.uk


I first heard of this book when Jeremy Miller (the maker of StructureMap) wrote that he was impressed by it. So I decided to purchase it, and now I have finished reading it. Before I give my conclusion, lets start with a summary of the different chapters in the book.

1. Architects and Architecture Today

Discusses the design of architecture and the role of the architect. Also gives a brief overview of different models for software development: Waterfall, Agile and Microsoft Solutions Framework.

2. UML Essentials

Covers the most important UML diagram types – Use Case, Class, and Sequence Diagrams. Describes three main modes of using UML – Sketch mode (emerging design), Blueprint mode (up front design), and Programming mode (Model-Driven Architecture).  The authors prefer to use UML as a sketching tool to communicate ideas, which seems like a sensible choice.

3. Design Principles and Patterns

Looks at goals of design principles and design – High Cohesion, Low Couping, and Separation of Concerns. Also looks at more advanced Object-Oriented Design principles – Open/Closed Principle, Liskov’s Substitution Principle, and Dependency Inversion Principle. Aspect-Oriented programming (AOP) is also explained by looking at Microsft’s Policy Injection Application Block.

This concludes the first part of the book, the rest of it looks at how to design a system by going through each application layer.

4. The Business Layer

Discusses different ways to organize business logic. The business logic can either be organized around user actions or around the domain. When organizing the logic around user actions, either the Transaction Script (TS) or Table Module (TM) pattern can be applied. These are best suited for low complexity in the domain. When organizing around the domain a Domain Model (DM) pattern can be applied. This pattern can deal with high complexity in the domain.

5. The Service Layer

The service layer is placed between the presentation layer and the business layer, it can also be thought as the upper part of the business layer. It basically is a list of actions that can be triggered from the user interface. One of its main responsibilities is dealing with roles and security. The chapter also discusses the following patterns that are related to the service layer – the Remote Facade Pattern, the Data Transfer Object Pattern, and the Adapter Pattern. It has a good discussion on when to use DTO’s and when it can be considered overkill. It gives a brief introduction to Service-Oriented Arhcitecture (SOA). Finally, it discusses the Serivice Layer in regards to AJAX.

6. The Data Access Layer

Starts off with a discussion of the responsibilities of a Data Access Layer (DAL), and how it “communicates” with the other layers. Then it describes patterns and principles to use when manually designing your own DAL – Service Locator, Inversion of Control, Transactions, Data Context, Query by Criteria, Unit of Work, Concurrency, and Lazy Loading. Afterwards it looks how an Object/Relational Mapper (OR/M) tool can be used to power the DAL, using NHibernate as an example. The authors consider NHibernate to be the de facto standard for O/RM tools, while Entity Framework (EF) is not yet mature enough. At the end of the chapter there is a great section called “To SP or Not to SP”, where the authors dispel many myths about Stored Procedures. At last, a book from Microsoft where SP are not described as the core of a DAL :)

7. The Presentation Layer

Presents the responsibilities of the presentation layer, and splits it into two segments – the user interface and presentation logic. Gives a great overview of the evolution of presentation patterns – Autonomous Views (AV), Model-View-Controller (MVC), Model2, Model-View-Presenter (MVP), and Presentation Model (PM). Also shows examples from different presentation frameworks – Web Client Software Factory, ASP.NET MVC Framework, MVC# Framework, and Windows Presentation Foundation.


I truly recommend this book to both intermediate and senior .NET developers. It has a great coverage of many current thoughts and aspects of system architecture. Many of the patterns in the book are from Patterns of Enterprise Application Architecture by Martin Fowler, and the book sets them into perspective in an enterprise .NET application. I like that a Microsoft Press book describes and even recommends Open Source tools, e.g. the book recommends NHibernate over Entity Framework. Dino’s writing is very consise and clear, and the book is full of code-examples, not just theory. However, since the scope of the book is very big, it cannot go into too much detail. So don’t expect to learn all you need about e.g. Domain Driven Design or NHibernate by reading this book.

Overall I give this book 4.5 of 5 stars :)

kick it on DotNetKicks.com Shout it

Tags: ,