NHibernate 4.x Cookbook - Second Edition

Author: Gunnar Liljas;Alexander Zaytsev;Jason Dentler  

Publisher: Packt Publishing‎

Publication year: 2017

E-ISBN: 9781784394110

P-ISBN(Paperback): 9781784396428

Subject: TP301.6 algorithm theory;TP31 computer software

Keyword: 计算机软件,算法理论,自动化技术、计算机技术

Language: ENG

Access to resources Favorite

Disclaimer: Any content in publications that violate the sovereignty, the constitution or regulations of the PRC is not accepted or approved by CNPIEC.

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

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

Chapter 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

Chapter 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

Using dictionaries as entities

Using NHibernate with transaction scope

Chapter 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

Chapter 5: Improving Performance

Reducing application startup time

Using MultiCriteria

Using MultiQuery

Using Futures

Eager loading child collections

Using stateless sessions

Using read-only entities

Use the second-level cache

Configuring the second-level cache with code

Sharding databases for performance

Chapter 6: Testing

Introduction

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

Introduction

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

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

Chapter 9: NHibernate Contribution Projects

Introduction

Property validation with attributes

Creating validator classes

Setting up full-text searches

Auditing data with Envers

Using NHibernate Spatial

Index

The users who browse this book also browse