NHibernate 2 Beginner's Guide

More Information
Learn
  • Use NHibernate to retrieve and store data in your database
  • Develop an efficient, robust data access layer with little or no code
  • Design or modify your database for high performance
  • Connect to multiple databases or database backends with simple code
  • Implement base classes to provide basic functionality for all database objects
  • Improve the performance of your data retrieval methods with proven open source technology
  • Make web applications faster using strong caching strategies such as memcached
  • Simplify data storage and display using built-in .NET data controls with NHibernate
  • Using NHibernate to control application security using Membership and Role providers and .NET security controls
About

NHibernate is an open source object-relational mapper, or simply put, a way to retrieve data from your database into standard .NET objects. Quite often we spend hours designing the database, only to go back and re-design a mechanism to access that data and then optimize that mechanism. This book will save you time on your project, providing all the information along with concrete examples about the use and optimization of NHibernate.

This book is an approachable, detailed introduction to the NHibernate object-relational mapper and how to integrate it with your .NET projects. If you're tired of writing stored procedures or maintaining inline SQL, this is the book for you.

Connecting to a database to retrieve data is a major part of nearly every project, from websites to desktop applications to distributed applications. Using the techniques presented in this book, you can access data in your own database with little or no code.

This book covers the use of NHibernate from a first glance at retrieving data and developing access layers to more advanced topics such as optimization and Security and Membership providers. It will show you how to connect to multiple databases and speed up your web applications using strong caching tools. We also discuss the use of third-party tools for code generation and other tricks to make your development smoother, quicker, and more effective.

Features
  • Incorporate robust, efficient data access into your .Net projects
  • Gain database independence, not tied to any particular technology
  • Avoid spending countless hours developing data access layers
  • Eliminate writing stored procedures
  • Clear, precise step-by-step directions to get up and running quickly
Page Count 276
Course Length 8 hours 16 minutes
ISBN 9781847198907
Date Of Publication 11 May 2010
Before you get started
Laying the foundation—table layouts
Time for action – creating an ordering system database
Table layouts
NHibernate assigned IDs
Relationships
Normal Form
Putting it all together
Time for action – adding some tables to our Ordering system database
Summary
What is mapping?
Types of mapping
XML mapping
Mapping our types
Time for action – mapping basic types
Relationships
Time for action – mapping relationships
Fluent mapping
Summary
What is an NHibernate session?
Time for action – getting ready
What is a session factory?
Creating your first session
Why do we call .Commit()?
NHibernate session versus database session?
Time for action – creating a session and doing some CRUD
Sessions in ASP.NET
Summary
Using Data Access Objects
The basic Data Access Object
Time for action – creating our basic Data Access Object
Data Access Object methods
Time for action – adding some CRUD methods
Coding some GetX() methods
The FieldNames structure
Time for action – expanding our capabilities
The ICriteria object
Creating a GetAll() method
Paging and Sorting GetAll() methods
Filtering ICriteria
Time for action – replacing our inline code
Summary

Authors

Aaron Cure

Aaron Cure is an avid developer, instructor, and innovator. During his 10 years in the military as a linguist and a satellite communications repair technician, he learned that his real love was computer programming. After various throes with PHP, Classic ASP, VB, and a brief encounter with Java/JSP, he found a real passion for the .NET framework. After searching for a "better way" to carry out database storage and retrieval, Aaron stumbled across the NHibernate framework. Unsatisfied with the options for interacting with this great framework, he founded the NHibernate Generation project (nhib-gen) on SourceForge to reduce the "barrier to entry" for most developers. Aaron and his family run a small consulting and web hosting company doing web design and custom software development for various organizations across the country. One of their more interesting projects has been software to control laser cutting machines. In his spare time, he also enjoys developing projects with his daughters, using everything from Lego NXT (using C# and Bluetooth communications) to the Microchip PIC platform (using JAL and USB). He also collects and restores classic farm tractors, engines, and farm equipment, as well as semi trucks and trailers. He and his family display them at tractor shows, parades, schools, and various other community events.