Description
Over 90 incredible and powerful recipes to help you efficiently use NHibernate in your application
About This Book
• Master the full range of NHibernate features through detailed example recipes that you can quickly apply to your own applications
• Reduce hours of application development time and get a better application architecture and improved performance
• Create, maintain, and update your database structure automatically with the help of NHibernate
Who This Book Is For
This book is written for .NET developers who want to use NHibernate and those who want to deepen their knowledge of the platform. Examples are written in C# and XML. Some basic knowledge of SQL is assumed. If you build .NET applications that use relational databases, this book is for you.
What You Will Learn
• Create a persistent object model to move data in and out of your database
• Build the database from your model automatically
• Configure NHibernate for use with WebForms, MVC, WPF, and WinForms applications
• Create database queries using a variety of methods
• Improve the performance of your applications using a variety of techniques
• Build an infrastructure for fast, easy, test-driven development of your data access layer
• Implement entity validation, auditing, full-text search, horizontal partitioning (sharding), and spatial queries using NHibernate Contrib projects
In Detail
NHibernate is a mature, flexible, scalable, and feature-complete open source project for data access. Although i
Chapter
Configuring NHibernate with hibernate.cfg.xml
Configuring NHibernate with App.config or Web.config
Configuring NHibernate with code
Configuring NHibernate with Fluent NHibernate
Configuring NHibernate logging
Using NHibernate schema tool
Chapter 2: Models and Mappings
Creating class hierarchy mappings
Creating class components
Mapping a one-to-many relationship
Mapping a many-to-many relationship
Mapping collections of elements and components
Setting up a base entity class
Handling versioning and concurrency
Creating mappings fluently
Bidirectional one-to-many class relationships
Mapping relations to non-primary keys
Using calculated properties
Using serializable values
Chapter 3: Sessions and Transactions
Setting up session-per-web request
Setting up session-per-presenter
Creating a session ASP.NET MVC action filter
Creating a transaction ASP.NET MVC action filter
Save entities to the database
Handle concurrency using session.Lock
Using dictionaries as entities
Using NHibernate with transaction scope
Using QueryOver projections and aggregates
Using the Hibernate Query Language
Eager loading with Criteria
Eager loading with QueryOver
Using HQL for bulk data changes
Using result transformers
Chapter 5: Improving Performance
Reducing application startup time
Eager loading child collections
Use the second-level cache
Configuring the second-level cache with code
Sharding databases for performance
Using NHibernate Profiler
Profiling NHibernate with Glimpse
Fast testing with the SQLite in-memory database
Preloading data with SQLite
Using Fluent NHibernate persistence testing
Using the Ghostbusters test
Chapter 7: Data Access Layer
Transaction auto-wrapping for the data access layer
Setting up an NHibernate repository
Using named queries in the data access layer
Using ICriteria in the data access layer
Using paged queries in the data access layer
Using LINQ specifications in the data access layer
Chapter 8: Extending NHibernate
Creating an encrypted string type
Using well-known instance types
Using dependency injection with entities
Creating an audit-event listener
Creation and change stamping of entities
Generating trigger-based auditing
Implementing a soft-delete pattern
Setting Microsoft SQL's Context_Info
Using dynamic connection strings
Using custom dialect functions
Using custom functions in LINQ
Extending the LINQ provider
Chapter 9: NHibernate Contribution Projects
Property validation with attributes
Creating validator classes
Setting up full-text searches
Auditing data with Envers