NHibernate 2 Beginner's Guide

Rapidly retrieve data from your database into .NET objects

NHibernate 2 Beginner's Guide

Aaron Cure

Rapidly retrieve data from your database into .NET objects
Mapt Subscription
FREE
$29.99/m after trial
eBook
$18.90
RRP $26.99
Save 29%
Print + eBook
$44.99
RRP $44.99
What do I get with a Mapt Pro subscription?
  • Unlimited access to all Packt’s 5,000+ eBooks and Videos
  • Early Access content, Progress Tracking, and Assessments
  • 1 Free eBook or Video to download and keep every month after trial
What do I get with an eBook?
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with Print & eBook?
  • Get a paperback copy of the book delivered to you
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with a Video?
  • Download this Video course in MP4 format
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
$0.00
$18.90
$44.99
$29.99p/m after trial
RRP $26.99
RRP $44.99
Subscription
eBook
Print + eBook
Start 30 Day Trial
Subscribe and access every Packt eBook & Video.
 
  • 5,000+ eBooks & Videos
  • 50+ New titles a month
  • 1 Free eBook/Video to keep every month
Start Free Trial
 
Preview in Mapt

Book Details

ISBN 139781847198907
Paperback276 pages

Book Description

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.

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!
Summary
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
Relationships
Normal Form
Putting it all together
Time for action – adding some tables to our Ordering system database
Summary
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
Summary
Chapter 4: Data Cartography
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
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
Summary
Chapter 6: I'm a Logger
Why do we need to log?
Why log4net?
Getting started
Configuration
Time for action – adding some logging
NHibernate log messages
Appenders
Creating a logger
Time for action – adding some custom logging
Summary
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
Summary
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
Summary
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>
Summary
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
Summary
Chapter 11: It's a Generation Thing
Judging requirements
CodeSmith
nhib-gen
AjGenesis
Visual NHibernate
MyGeneration
Time for action – using MyGeneration
NGen NHibernate Code Generator
NHModeller
Microsoft T4 templates
T4 hbm2net
Summary
Chapter 12: Odds and Ends
Unit of Work and Burrow
How does this relate to NHibernate?
Blog.Net blogging components
maxRequestLength
Converting CSS templates
Time for action – converting a CSS template
XML documentation & GhostDoc
Summary

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

Authors

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!
Summary
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
Relationships
Normal Form
Putting it all together
Time for action – adding some tables to our Ordering system database
Summary
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
Summary
Chapter 4: Data Cartography
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
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
Summary
Chapter 6: I'm a Logger
Why do we need to log?
Why log4net?
Getting started
Configuration
Time for action – adding some logging
NHibernate log messages
Appenders
Creating a logger
Time for action – adding some custom logging
Summary
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
Summary
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
Summary
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>
Summary
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
Summary
Chapter 11: It's a Generation Thing
Judging requirements
CodeSmith
nhib-gen
AjGenesis
Visual NHibernate
MyGeneration
Time for action – using MyGeneration
NGen NHibernate Code Generator
NHModeller
Microsoft T4 templates
T4 hbm2net
Summary
Chapter 12: Odds and Ends
Unit of Work and Burrow
How does this relate to NHibernate?
Blog.Net blogging components
maxRequestLength
Converting CSS templates
Time for action – converting a CSS template
XML documentation & GhostDoc
Summary

Book Details

ISBN 139781847198907
Paperback276 pages
Read More

Read More Reviews

Recommended for You

NHibernate 3.0 Cookbook Book Cover
NHibernate 3.0 Cookbook
$ 26.99
$ 18.90
ODP.NET Developer's Guide: Oracle Database 10g Development with Visual Studio 2005 and the Oracle Data Provider for .NET Book Cover
ODP.NET Developer's Guide: Oracle Database 10g Development with Visual Studio 2005 and the Oracle Data Provider for .NET
$ 29.99
$ 21.00
Oracle 10g/11g Data and Database Management Utilities Book Cover
Oracle 10g/11g Data and Database Management Utilities
$ 29.99
$ 21.00
NHibernate 3 Beginner's Guide Book Cover
NHibernate 3 Beginner's Guide
$ 26.99
$ 18.90
Mastering Web Application Development with AngularJS Book Cover
Mastering Web Application Development with AngularJS
$ 26.99
$ 5.40
Oracle Database XE 11gR2 Jump Start Guide Book Cover
Oracle Database XE 11gR2 Jump Start Guide
$ 17.99
$ 12.60