Preface

Connecting the object-oriented world of .NET to the relational world of databases has always been a fiddly issue. With the onset of ORMs, such as NHibernate, developers have got some relief in this area. However, using NHibernate without understanding its core features, and how they work, can always lead to more fiddly code and frustration. Learning how to use NHibernate in practical scenarios with the help of proven patterns and techniques goes a long way to building a robust data access layer. Knowing the best practices of designing a data access layer with NHibernate, before you start your next project, will help you to avoid any problems and deliver a successful project.

What this book covers

Chapter 1, Introduction to NHibernate, provides a view of NHibernate from 10,000 feet above and touches upon topics such as what an ORM is and why developers should use it. New features of NHibernate 4.0 are examined in this chapter along with the basic building blocks of NHibernate.

Chapter 2, Let's Build a Simple Application, describes a problem statement and builds a very simple domain model, so that we have a set of known business requirements to refer to in the rest of the book. This chapter also covers different software and tools that we will use throughout the book.

Chapter 3, Let's Tell NHibernate About Our Database, takes a deep dive into one of the building blocks of NHibernate –– mapping. The chapter starts with a brief introduction to the different mechanisms of mapping supported by NHibernate. The rest of the chapter goes into the details of mapping classes, properties, identifiers, associations, and inheritance hierarchies. In this chapter, the domain model defined in Chapter 2, Let's Build a Simple Application, is mapped to an appropriate database schema.

Chapter 4, NHibernate Warm-up, walks through the configuration of NHibernate. The chapter starts with a discussion on the different ways of configuring NHibernate and the minimal configurations required to get it up and running. Many important, but optional, configurations that include caching, session context, batch size, and so on, are covered next. The chapter ends with a discussion on generating database creation and updating scripts using NHibernate mappings.

Chapter 5, Let's Store Some Data into the Database, in a nutshell covers the NHibernate API that saves data in database. Beyond this, this chapter covers important concepts such as transactions, flush modes, cascades, and inverse collections. This chapter explains how transitive persistence works in different scenarios. Entity equality and its implementation in the context of NHibernate is provided in this chapter.

Chapter 6, Let's Retrieve Some Data from the Database, as the name suggests, talks about retrieving data from the database using the different querying methods supported by NHibernate. The book stresses using LINQ but other methods, namely native SQL, HQL, Criteria API and QueryOver, are also introduced and covered in detail wherever required. The chapter goes into the details of important concepts such as joins, lazy loading, eager fetching, and polymorphic queries. Basic querying requirements such as sorting and ordering the results are explained in this chapter.

Chapter 7, Optimizing the Data Access Layer, talks about making the NHibernate code more efficient by making use of techniques such as batching, different fetching strategies, and avoiding "select N+1" and eager fetching.

Chapter 8, Using NHibernate in a Real-world Application, introduces some architectural principles such as onion architecture and dependency injection that will help in building a robust data access layer using NHibernate in production code. This chapter covers important concepts, such as unit of work and session per request along with their implementation in NHibernate. Repository pattern, the most commonly used pattern for abstracting the low level details of data access code, is also covered in this chapter.

Chapter 9, Advanced Data Access Patterns, begins with a discussion on the shortcomings of repository pattern. The chapter then introduces two data access patterns, namely specification pattern and query object pattern, which address the shortcomings of repository pattern.

Chapter 10, Working with Legacy Database, goes into the NHibernate features that come handy in legacy database situations –– where database schema is not ideal for the domain model at hand. The chapter talks about composite IDs, components, working with database views, stored procedures, and custom DTOs. Custom lazy loading retention is introduced, so that it can be used with DTOs when there is a chance that NHibernate's lazy loading is rendered ineffective.

Chapter 11, A Whirlwind Tour of Other NHibernate Features, talks about the features of NHibernate that are slightly advanced and are not touched upon in any of the previous chapters. Important features such as concurrency control, event system, caching, and user-defined types are covered along with practical examples of their usage.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.226.255