万本电子书0元读

万本电子书0元读

顶部广告

Learning NHibernate 4电子书

售       价:¥

0人正在读 | 0人评论 9.8

作       者:Suhas Chatekar

出  版  社:Packt Publishing

出版时间:2015-07-31

字       数:309.0万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
This book targets .NET developers who have never used an ORM before, developers who have used an ORM before but are new to NHibernate, or have used NHibernate sparingly and want to learn more about NHibernate.
目录展开

Learning NHibernate 4

Table of Contents

Learning NHibernate 4

Credits

About the Author

About the Reviewers

www.PacktPub.com

Support files, eBooks, discount offers, and more

Why subscribe?

Free access for Packt account holders

Preface

What this book covers

What you need for this book

Who this book is for

Conventions

Reader feedback

Customer support

Downloading the example code

Errata

Piracy

Questions

1. Introduction to NHibernate

What is ORM?

What is NHibernate?

What is new in NHibernate 4.0?

NHibernate for users of Entity Framework

Is using ORM a bad idea?

Why ORM is a better bet?

Non-functional features required by the data access layer

Building blocks of NHibernate

Mappings

Configuration

Session

Summary

2. Let's Build a Simple Application

Explaining the approach used in learning NHibernate

The problem statement

The development setup

Visual Studio 2013

SQL Server 2012 Express

ReSharper

NUnit

NuGet

SQLite

The domain model

Employee

Leave

SeasonTicketLoan

SkillEnhancementAllowance

Adding some code

Adding the NuGet packages to projects

Back to our test

Summary

3. Let's Tell NHibernate About Our Database

Important NHibernate terminology

Mapping the prerequisites

Different mechanisms to write the mappings

XML mappings

Fluent mapping

Mapping by code

XML mappings for the Employee class

Getting the development environment ready

Getting IntelliSense to work with the XML mapping files

Unit tests to verify the Employee mappings

The mappings

Hibernate-mapping

Class

Property

Identifier generation

Identity

Sequence

Hilo

Seqhilo

GUID

Guid.comb

Native

Assigned

Mapping associations

Associations and database tables

One-to-many association

Types of collections

Many-to-one association

One-to-one association

Many-to-many association

Mapping inheritance

Unit tests to verify the inheritance mappings

Table per class hierarchy

Table per subclass

Table per concrete class

Choosing the right inheritance mapping strategy

Mapping components

Mapping by code

Identifier

Property

Association

One-to-many

Many-to-one

One-to-one

Many-to-many

Component

Inheritance

Table per class hierarchy

Table per subclass

Table per concrete class

Complete mappings by code for the employee benefits domain

Fluent mapping a.k.a. Fluent NHibernate

Inheritance mappings

Table per class hierarchy

Table per concrete class

Table per subclass

Component mapping

Choosing the right mapping method

Summary

4. NHibernate Warm-up

Warming up NHibernate succinctly

The NHibernate session architecture

XML configuration

Programmatic configuration

Loquacious configuration

Fluent configuration

Configuration options

Connection release mode

Dialect

Driver

Mappings

Programmatic configuration

XML mapping

Mapping by code

Fluent configuration

Connection string

Caching

Session context

Batch size

Command timeout

Show SQL

Generating the database scripts from mappings

The database creation script

The database update scripts

Automatically create/update the database schema

Summary

5. Let's Store Some Data into the Database

Entity states

Transactions and unit of work

Explicit and implicit transactions

Flush modes

Saving entities

Saving entities – complex scenarios

Transitive persistence using cascade styles

Transitive persistence/cascading in action

Saving a transient entity with association to other transient entities

A word on bidirectional associations

Updating associations on a persistent entity

Deleting a persistent entity with one or more associations set

Bidirectional associations and ownership

Ownership in many-to-many associations

Inverse and cascade

Order of operations

Entity equality

Why does equality matter?

Implementing equality

The architecture diagram

Summary

6. Let's Retrieve Some Data from the Database

Querying the workflow

Different querying methods

Native SQL

Hibernate Query Language

Parameter binding

Criteria API

Filtering the criteria queries

The QueryOver API

LINQ

Which querying method should I use?

Joins

Different types of joins

Implicit joins

QueryOver joins explained

JoinAlias

Outer joins

Theta style joins

Lazy loading

Lazy collections

Disabling laziness

Different lazy behaviors

Single-ended lazy associations

Proxy versus NoProxy

Lazy properties

Why use lazy loading?

Lazy loading gotcha's

Keeping the session open

Being aware of the select N+1 problem

Using lazy loading together with the right fetching strategy

Using automatic properties

Eager fetching

HQL

Criteria

QueryOver

LINQ

Pagination and ordering of results

Narrowing down the number of records returned by a query

Ordering the results

Retrieving entities by identifiers

Why use Load<T>?

Polymorphic queries

Summary

7. Optimizing the Data Access Layer

Baseline and optimize

Organization of the chapter

Batching

Batching the write queries using ADO.NET batching

Limitations of batching

Memory consumption and batching

Read batching using future queries

Batching lazy collections

Fetching strategies


Select fetching

Join fetching

Subselect fetching

Choosing the right fetching strategy

Avoiding the select N+1 problem

What is the select N+1 problem?

Why select N+1 is a problem?

How do we fix the select N+1 problem?

Avoiding eager fetching

Future queries to the rescue

Using extra-lazy for lazy collections

Summary

8. Using NHibernate in a Real-world Application

What kind of application are we building?

Architectural principles we will follow

No anaemic domain model

The onion architecture

Dependency inversion

Explicitly declaring the capabilities required

Unit of work

Feature 1 – onboarding an employee

Repository pattern

Where does the repository belong?

Back to onboarding an employee

Unit of work

Scope of unit of work for web applications

Session per request

Contextual sessions

Configuring CurrentSessionContext

Implementing session per request using the contextual sessions

Using the HTTP module

Using hooks in the global.ascx file

Using the action filters of ASP.NET MVC or Web API

WCF

Unit of work implementation

Unit of work spanning the whole HTTP request

Unit of work with custom scope

Feature 2 – updating the details of an employee

Updates using transitive persistence

Updating the detached entities

Why transitive persistence is better

Feature 3 – searching employees

Summary

9. Advanced Data Access Patterns

Problems with the repository pattern

Generalization

Unclear and confusing contract

Leaky abstraction

God object anti-pattern

Specification pattern

Specification pattern in its original form

Specification pattern for NHibernate

Specification chaining

Limitations

Query object pattern

Extending the query object pattern

The limitations of the query object pattern

Summary

10. Working with Legacy Database

Composite IDs

Composite foreign key

Components

Join-mapping to load data from multiple tables

Working with database views

Using subselect instead of views

Working with stored procedures

Using custom DTOs

Right place for DTOs

The conversion layer

Downsides of using custom DTOs

Custom lazy loading retention

Summary

11. A Whirlwind Tour of Other NHibernate Features

Concurrency control

Optimistic concurrency control

Using optimistic-lock

Using the version property

Pessimistic concurrency control

Event system

Event listeners

Adding the audit trail for entities

Caching

Session level cache

Second level cache

Query cache

Stateless sessions

User-defined types

Other user-defined types

Summary

Index

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部