Chapter 23. Data access with NHibernate
This chapter covers
- Decoupling data access from the core and UI
- Configuring NHibernate mappings
- Bootstrapping NHibernate
- Invoking data access from ASP.NET MVC
Even though the ASP.NET MVC Framework is focused on the presentation layer, many developers work on small applications that don’t need several layers of business logic and separation between the presentation layer and the data store. For these small applications, simple separation patterns may be appropriate, but many small applications grow much larger than originally anticipated. When this happens, separation of concerns is critical to the long-term maintainability of the software.
To achieve separation of concerns when communicating with a relational database, we can use an object-relational mapping tool such as the popular open source NHibernate project. NHibernate makes data access with relational databases trivial. As with anything new, a learning curve is associated with understanding the method of configuring the mapping between objects and tables. This chapter demonstrates how to configure and leverage NHibernate when developing an application whose UI takes advantage of the ASP.NET MVC Framework. This example is equally applicable in ASP.NET MVC 1 and 2.