NHibernate 4.x Cookbook - Second Edition
图书信息
| 作者 | Gunnar Liljas |
| 出版社 | Packt Publishing |
| ISBN | 9781784394110 |
| 出版时间 | 2017-01-01 |
| 字数 | 361.2万 |
| 分类 | 进口书,外文原版书,电脑,网络 |
读书简介
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.
目录
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
eBooks, discount offers, and more
Why Subscribe?
Customer Feedback
Preface
What this book covers
What you need for this book
Who this book is for
Sections
Getting ready
How to do it…
How it works…
There's more…
See also
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. The Configuration and Schema
Introduction
Installing NHibernate
Getting ready
How to do it...
There's more…
Configuring NHibernate with hibernate.cfg.xml
Getting ready
How to do it...
How it works...
There's more...
NHibernate architecture
NHibernate properties
Dialects and drivers
See also
Configuring NHibernate with App.config or Web.config
Getting ready
How to do it…
How it works…
There's more…
See also
Configuring NHibernate with code
Getting ready
How to do it…
How it works…
There's more...
See also
Configuring NHibernate with Fluent NHibernate
Getting ready
How to do it…
How it works…
See also
Configuring NHibernate logging
Getting ready
How to do it...
How it works...
There's more...
Using logger to troubleshoot NHibernate
Using other log providers
See also
Generating the database
Getting ready
How to do it...
How it works...
There's more...
See also
Scripting the database
Getting ready
How to do it...
How it works...
See also
Updating the database
Getting ready
How to do it...
How it works...
See also
Using NHibernate schema tool
Getting ready
How to do it...
How it works...
There's more...
See also
2. Models and Mappings
Mapping a class with XML
Getting ready
How to do it…
How it works…
There's more…
What happens to these mappings?
Surrogate keys and natural IDs
ID generator selection
See also
Creating class hierarchy mappings
Getting ready
How to do it…
How it works…
There's more…
Table per class
Table per concrete class
See also
Creating class components
Getting ready
How to do it…
How it works…
Mapping a one-to-many relationship
Getting ready
How to do it…
How it works…
There's more…
Lazy loading collections
Lazy loading proxies
Collections
Bags
Lists
Sets
Map
See also
Mapping a many-to-many relationship
Getting ready
How to do it…
How it works…
There's more…
Mapping collections of elements and components
Getting ready
How to do it…
How it works…
There's more…
Setting up a base entity class
How to do it…
How it works…
There's more…
See also
Handling versioning and concurrency
Getting ready
How to do it…
How it works…
There's more…
See also
Mapping by code
Getting ready
How to do it…
How it works…
There's more…
See also
Mapping by convention
Getting ready
How to do it…
How it works…
There's more…
Creating mappings fluently
Getting ready
How to do it…
How it works…
See also
Bidirectional one-to-many class relationships
How to do it…
How it works…
There's more…
Mapping enumerations
How to do it…
How it works…
Unnecessary updates
See also
Immutable entities
Getting ready
How to do it…
How it works…
Mapping relations to non-primary keys
Getting ready
How to do it…
How it works…
There's more…
Using lazy properties
Getting ready
How to do it…
How it works…
Mapping joins
Getting ready
How to do it…
How it works…
There's more…
Using calculated properties
Getting ready
How to do it…
How it works…
There's more…
Using serializable values
Getting ready
How to do it…
How it works…
There's more…
Dynamic components
Getting ready
How to do it…
How it works…
There's more…
Mapping
Getting ready
How to do it…
How it works…
3. Sessions and Transactions
Introduction
Setting up session-per-web request
Getting ready
Option 1: Using the companion library
Option 2: Manual setup
How to do it…
How it works…
There's more…
See also
Setting up session-per-presenter
How to do it…
How it works…
There's More…
See also
Creating a session ASP.NET MVC action filter
Getting ready
How to do it…
How it works…
What about Web API?
There's more…
View models
See also
Creating a transaction ASP.NET MVC action filter
Getting ready
How to do it…
How it works…
There's more…
Save entities to the database
Getting ready
How to do it…
How it works…
Save
Update
SaveOrUpdate
Persist
Using different flush modes
Commit
Auto
Always
Never
Using session.Merge
Getting ready
How to do it…
How it works…
See also
Using session.Refresh
Getting ready
How to do it…
How it works…
There's more…
See also
Handle concurrency using session.Lock
Getting ready
How to do it…
How it works…
None
Read
Upgrade
UpgradeNoWait
There's more…
Using dictionaries as entities
Getting ready
How to do it...
How it works…
There's more…
Partially dynamic
Using NHibernate with transaction scope
Getting ready
How to do it…
How it works…
See also
4. Queries
Introduction
Getting ready
Query entities by ID
Getting ready
How to do it…
How it works…
Session.Get
Session.Load
The session cache jumps in
Using LINQ to NHibernate
Getting ready
How to do it…
How it works…
There's more…
See also
Using CriteriaQueries
Getting ready
How to do it…
How it works…
There's more…
See also
Using QueryOver
Getting ready
How to do it…
How it works…
There's more…
See also
Using QueryOver projections and aggregates
Getting ready
How to do it…
How it works…
See also
Using the Hibernate Query Language
Getting ready
How to do it…
How it works…
There's more…
See also
Using native SQL
Getting ready
How to do it…
How it works…
Eager loading with LINQ
Getting ready
How to do it…
How it works…
There's more…
Limiting the result set doesn't work
Eager loading multiple collections should be avoided
Use batching as an alternative solution
See also
Eager loading with Criteria
Getting ready
How to do it…
How it works…
Eager loading with QueryOver
Getting ready
How to do it…
How it works…
Eager loading with HQL
Getting ready
How to do it…
How it works…
Eager loading with SQL
Getting ready
How to do it…
How it works…
Using named queries
Getting ready
How to do it…
How it works…
Named SQL queries
There's more…
See also
Using detached queries
Getting ready
How to do it…
How it works…
There's more…
See also
Using HQL for bulk data changes
Getting ready
How to do it…
How it works…
There's more…
Bulk inserts
See also
Filtering collections
Getting ready
How to do it…
How it works…
There's more…
Using result transformers
How to do it…
How it works…
There's more…
DistinctRootEntity
AliasToEntityMap
PassThrough
RootEntity
ToList
AliasToBean
AliasToBeanConstructor
Creating your own transformer
Extra lazy collections
Getting ready
How to do it…
How it works…
There's more…
5. Improving Performance
Reducing application startup time
Getting ready
How to do it…
How it works…
There's more…
Using MultiCriteria
Getting ready
How to do it…
How it works…
See also
Using MultiQuery
Getting ready
How to do it…
How it works…
See also
Using Futures
Getting ready
How to do it...
How it works...
There's more...
See also
Eager loading child collections
Getting ready
How to do it...
How it works...
Problem 1 – limiting the result set doesn't work
Problem 2 – only the queried class' properties can be eager loaded
Problem 3 – eager loading multiple collections should be avoided
There's more…
Criteria
QueryOver
See also
Using stateless sessions
Getting ready
How to do it...
How it works...
There's more...
Using read-only entities
Getting ready
How to do it...
How it works...
Setting the session to be read-only
Setting a query to load entities as read-only
Making a specific entity read-only
There's more...
Use the second-level cache
Getting ready
How to do it...
How it works...
There's more...
Entity cache
Query cache
Update timestamp cache
The rules
See also
Configuring the second-level cache with code
Getting ready
How to do it...
How it works...
There's more…
See also
Sharding databases for performance
Getting ready
How to do it...
How it works...
6. Testing
Introduction
Using NHibernate Profiler
Getting ready
How to do it...
How it works...
There's more...
See also
Profiling NHibernate with Glimpse
Getting ready
How to do it...
How does it work...
See also
Fast testing with the SQLite in-memory database
Getting ready
How to do it...
How it works...
There's more...
See also
Preloading data with SQLite
Getting ready
How to do it...
How it works...
There's more...
See also
Using Fluent NHibernate persistence testing
Getting ready
How to do it...
How it works...
See also
Using the Ghostbusters test
Getting ready
How to do it...
How it works...
See also
7. Data Access Layer
Introduction
Transaction auto-wrapping for the data access layer
Getting ready
How to do it…
How it works…
There's more…
See also
Setting up an NHibernate repository
Getting ready
How to do it…
How it works…
There's more…
See also
Using named queries in the data access layer
Getting ready
How to do it…
How it works…
See also
Using ICriteria in the data access layer
Getting ready
How to do it…
How it works…
There's more…
See also
Using paged queries in the data access layer
Getting ready
How to do it…
How it works…
See also
Using LINQ specifications in the data access layer
Getting ready
How to do it…
How it works…
There's more…
Specification composition
See also
8. Extending NHibernate
Introduction
Creating an encrypted string type
How to do it…
How it works…
There's more…
See also
Creating a money type
How to do it…
How it works…
There's more…
See also
Using well-known instance types
How to do it…
How it works…
See also
Using dependency injection with entities
Getting ready
How to do it…
How it works…
There's more…
Bland passwords need salt
See also
Creating an audit-event listener
How to do it…
How it works…
There's more…
See also
Creation and change stamping of entities
How to do it…
How it works…
See also
Generating trigger-based auditing
Getting ready
How to do it…
How it works…
See also
Implementing a soft-delete pattern
How to do it…
How it works…
There's more…
See also
Setting Microsoft SQL's Context_Info
Getting ready
How to do it…
How it works…
See also
Using dynamic connection strings
How to do it…
How it works…
See also
Using custom dialect functions
How to do it…
How it works…
See also
Using custom functions in LINQ
Getting ready
How to do it…
How it works…
See also
Extending the LINQ provider
Getting ready
How to do it…
How it works…
See also
9. NHibernate Contribution Projects
Introduction
Property validation with attributes
Getting ready
How to do it…
How it works…
There's more…
See also
Creating validator classes
Getting ready
How to do it…
How it works…
There's more…
See also
Setting up full-text searches
Getting ready
How to do it…
How it works…
There's more…
Auditing data with Envers
Getting ready
How to do it…
How it works…
There's more…
See also
Using NHibernate Spatial
Getting ready
How to do it…
How it works…
There's more…
Geography or geometry?
What's this SRID?
Spatial data types
Index
- 工业大麻生物技术研究进展(张利国)
- 应用文写作(倪斯雯)
- (四色)世界名人非常之路.医学世家走出的医圣:李时珍(王莲凤)
- 传统中国法叙事(张守东)
- 古代世界数学泰斗刘徽(郭书春)
- 地方数字政府建设中的政企关系(蔡聪裕)
- 小学语文课外阅读世界文学经典名著:克雷洛夫寓言(克雷洛夫)
- 夏威夷-走遍全球-第2版(日本大宝石出版社)
