Elastic Scale with Azure DB - Entity Framework Integration


Entity Framework, Windows Azure SQL Database, Elastic Scale
Entity Framework, Scalability, Elastic Scale
Cloud, Data
en-US
3/6/2015

Introduction

Azure SQL Database Elastic Scale (in preview) enables the data-tier of an application to scale out via industry-standard sharding practices while significantly streamlining the development and management experience of your sharded cloud applications. This sample application is shows how you can benefit from sharding using Elastic Scale for application you develop with Entity Framework.

Building the Sample

After downloading the sample in Visual Studio, you first need to create three new databases in Azure SQL DB. Once the databases are up and running in Azure, fill in the place holders for your Azure SQL DB credentials and the database names in the beginning of the file Program.cs. You are then ready to build and run the sample. When building the sample, Visual Studio will download the libraries for Elastic Scale, Entity Framework and Transient Fault Handling.

Description

The sample adopts the popular blogging example from Entity Framework and highlights the changes that are necessary to embrace sharding at the data tier for your Entity Framework application. The most important changes are about creating your DbContext instances. Instead of using the default DbContext subclasses, the sample introduces a different overload of the DbContext constructors in the DbContext subclass. That constructor now also takes the information about the sharding metadata by means of the ShardMap input parameter. This allows the new DbContext subclass to broker connections across many separate Azure SQL Db databases using Elastic Scale shard maps. With this limited set of changes to the places in your code where you create new DbContext, you can enable Data Dependent Routing through Elastic Scale for your EF applications.

Another important aspect of Entity Framework is its ability to bootstrap the schema of the application on an empty new database using Entity Framework migrations. This is particularly compelling in the context of a sharded data tier approach where new databases are created as the application needs more capacity. This sample also illustrates how you can combine Entity Framework migrations with the registration of new shards with Elastic Scale. That way, you do not have to worry about creating the database schema manually on new shards, just like with regular EF applications.

Next Steps

Azure SQL Database with Elastic Scale provides you with powerful capabilities to elastically scale the data tier of your cloud applications in tandem with the changing capacity needs of your business. If you enjoyed this sample application, continue further exploring Elastic Scale and its capabilities here: http://go.microsoft.com/?linkid=9862897.