There are a few scenarios where it may be appropriate to partition data horizontally across several servers, with performance being the most obvious reason. The concept itself is known as sharding and is used in many large scale applications, such as Facebook.
In this recipe, we'll show you how to use NHibernate.Shards
to split our data set across three databases.
In SQL Server, create three new, blank databases named Shard1, Shard2, and Shard3. Complete the Getting Ready instructions at the beginning of Chapter 4, Queries.
Add a reference to
NHibernate.Shards
using NuGet Package Manager Console:Install-Package NHibernate.Shards –Project QueryRecipes
Add a new folder named
Sharding
to the project:Add a new embedded resource named
ShardedProduct.hbm.xml
:<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="QueryRecipes" namespace="QueryRecipes.Sharding"> <class...