Free Sample
+ Collection

NHibernate 2 Beginner's Guide

Beginner's Guide
Aaron Cure

Rapidly retrieve data from your database into .NET objects
RRP $26.99
RRP $44.99
Print + eBook

Want this title & more?

$12.99 p/month

Subscribe to PacktLib

Enjoy full and instant access to over 2000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.

Book Details

ISBN 139781847198907
Paperback276 pages

About This Book

  • 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

Who This Book Is For

This book is for new and seasoned developers of .NET web or desktop applications who want a better way to access database data. It is a basic introduction to NHibernate, with enough information to get a solid foundation in using NHibernate. Some advanced concepts are presented where appropriate to enhance functionality or in situations where they are commonly used.

Table of Contents

Chapter 1: First Look
What is NHibernate?
Why would I use it?
Where do I get it?
Can I get help using NHibernate?
Database table
The XML mapping file (hbm.xml)
Plain Old CLR Object ( POCO )
Data access
Look how easy it is to use!
Chapter 2: Database Layout and Design
Before you get started
Laying the foundation—table layouts
Time for action – creating an ordering system database
Table layouts
NHibernate assigned IDs
Normal Form
Putting it all together
Time for action – adding some tables to our Ordering system database
Chapter 3: A Touch of Class
Start up our applications
Creating objects
Time for action – creating our first class
Public properties and private variables
Time for action – adding a few properties
Converting SQL database types to .NET types
Properties for Foreign Keys
Chapter 4: Data Cartography
What is mapping?
Types of mapping
XML mapping
Mapping our types
Time for action – mapping basic types
Time for action – mapping relationships
Fluent mapping
Chapter 5: The Session Procession
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
Chapter 6: I'm a Logger
Why do we need to log?
Why log4net?
Getting started
Time for action – adding some logging
NHibernate log messages
Creating a logger
Time for action – adding some custom logging
Chapter 7: Configuration
Looking back
The basics of configuration
Taking a look at the SQL
Abstracting the configuration
Time for action – moving our configuration
XML configuration
Chapter 8: Writing Queries
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
Chapter 9: Binding Data
Why should we use data binding?
Time for action – adding an ASP.NET project
Basic data binding techniques
Common data binding methods
A simple templated control
Creating a control instance
The <asp:ListView> control
The <asp:ObjectDataSource> control
Time for action – adding our first data bound control
Direct data binding
One last control—the <asp:FormView>
Chapter 10: .NET Security
Built-in controls
Time for action – adding a login to our page
Membership providers
Location security
Configuring our provider
Time for action – create a membership provider
User roles
Role providers
Provider configuration
Chapter 11: It's a Generation Thing
Judging requirements
Visual NHibernate
Time for action – using MyGeneration
NGen NHibernate Code Generator
Microsoft T4 templates
T4 hbm2net
Chapter 12: Odds and Ends
Unit of Work and Burrow
How does this relate to NHibernate?
Blog.Net blogging components
Converting CSS templates
Time for action – converting a CSS template
XML documentation & GhostDoc

What You Will 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

In Detail

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.


Read More