Book 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 it sounds like an easy task to build and maintain database applications, it can be challenging to get beyond the basics and develop applications that meet your needs perfectly. NHibernate allows you to use plain SQL and stored procedures less and keep focus on your application logic instead. Learning the best practices for a NHibernate-based application will help you avoid problems and ensure that your project is a success.
The book will take you from the absolute basics of NHibernate through to its most advanced features, showing you how to take full advantage of each concept to quickly create amazing database applications. You will learn several techniques for each of the four core NHibernate tasks - configuration, mapping, session and transaction management, and querying - and which techniques fit best with various types of applications. In short, you will be able to build an application using NHibernate by the end of the book.
You will also learn how to best implement enterprise application architecture patterns using NHibernate, leading to clean, easy-to-understand code and increased productivity. In addition to new features, you will learn creative ways to extend the NHibernate core, as well as gaining techniques to work with the NHibernate search, shards, spatial, envers, and validation projects.
Style and approach
This book contains recipes with examples organized in functional areas, each containing step-by-step instructions on everything necessary to execute a particular task. The book is designed so you can read it from start to end or just open up any chapter and start following the recipes.
Table of contents
-
NHibernate 4.x Cookbook Second Edition
- Table of Contents
- NHibernate 4.x Cookbook Second Edition
- Credits
- About the Authors
- About the Reviewer
- www.PacktPub.com
- Customer Feedback
- Preface
-
1. The Configuration and Schema
- Introduction
- Installing NHibernate
- 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
- Generating the database
- Scripting the database
- Updating the database
- Using NHibernate schema tool
-
2. Models and Mappings
- Mapping a class with XML
- 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
- Mapping by code
- Mapping by convention
- Creating mappings fluently
- Bidirectional one-to-many class relationships
- Mapping enumerations
- Immutable entities
- Mapping relations to non-primary keys
- Using lazy properties
- Mapping joins
- Using calculated properties
- Using serializable values
- Dynamic components
- Mapping <subselect>
-
3. Sessions and Transactions
- Introduction
- 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
- Using session.Merge
- Using session.Refresh
- Handle concurrency using session.Lock
- There's more…
- Using dictionaries as entities
- Using NHibernate with transaction scope
-
4. Queries
- Introduction
- Query entities by ID
- Using LINQ to NHibernate
- Using CriteriaQueries
- Using QueryOver
- Using QueryOver projections and aggregates
- Using the Hibernate Query Language
- Using native SQL
- Eager loading with LINQ
- Eager loading with Criteria
- Eager loading with QueryOver
- Eager loading with HQL
- Eager loading with SQL
- Using named queries
- Using detached queries
- Using HQL for bulk data changes
- Filtering collections
- Using result transformers
- Extra lazy collections
- 5. Improving Performance
- 6. Testing
- 7. Data Access Layer
-
8. Extending NHibernate
- Introduction
- Creating an encrypted string type
- Creating a money 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
- 9. NHibernate Contribution Projects
- Index
Product information
- Title: NHibernate 4.x Cookbook - Second Edition
- Author(s):
- Release date: January 2017
- Publisher(s): Packt Publishing
- ISBN: 9781784396428
You might also like
book
Learning NHibernate 4
Explore the full potential of NHibernate to build robust data access code In Detail Connecting the …
book
Working with NHibernate 3.0
This book provides examples using the IQuery, ICriteria, QueryOver, and LINQ to NHibernate API's within the …
book
NHibernate in Action
In the classic style of Manning's "In Action" series, NHibernate in Action introduces .NET developers to …
book
Dojo Fundamentals: Creating Object-Oriented Widgets
This Short Cut was formally titled "Get Up and Running with Dojo." This updated version has …