NHibernate 4.x Cookbook - Second Edition
eBook - ePub

NHibernate 4.x Cookbook - Second Edition

  1. 448 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

NHibernate 4.x Cookbook - Second Edition

About this book

Over 90 incredible and powerful recipes to help you efficiently use NHibernate in your applicationAbout 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 NHibernateWho This Book Is ForThis 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 projectsIn DetailNHibernate 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 approachThis 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.

Tools to learn more effectively

Saving Books

Saving Books

Keyword Search

Keyword Search

Annotating Text

Annotating Text

Listen to it instead

Listen to it instead

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 <subselect>
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
Gettin...

Table of contents

  1. NHibernate 4.x Cookbook Second Edition

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 990+ topics, we’ve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access NHibernate 4.x Cookbook - Second Edition by Gunnar Liljas, Alexander Zaytsev, Jason Dentler in PDF and/or ePUB format, as well as other popular books in Computer Science & Application Development. We have over one million books available in our catalogue for you to explore.