Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Entity Framework 6 Alpha 3 with Code First Stored Procedures and Connection Resiliency

Entity Framework 6 Alpha 3 with Code First Stored Procedures and Connection Resiliency

This item in japanese

Microsoft has announced the availability of Entity Framework 6 Alpha 3 with support for code first mapping to insert, update, delete stored procedures with the help of fluent API, connection resiliency, pull request from iceclow, UnaiZorrilla and new DbContext API scenarios that enables you to manage your own transactions.

According to Microsoft, three stored procedures should be created in format such as <type_name>_Insert, <type_name>_Update and <type_name>_Delete. Moreover, the parameter names correspond to the property names and insert and update stored procedures should include a parameter for every property except for those marked as identity or computed and the delete stored procedure should have a parameter for the key value of the entity.

Let us take a look at the following code snippet

public class Blog
  public int BlogId { get; set; }
  public string Name { get; set; }
  public string Url { get; set; }

The insert stored procedure corresponding to the above code should look like as shown below

CREATE PROCEDURE [dbo].[Blog_Insert]
  @Name varchar(max),
  @Url varchar(max)
  INSERT INTO [dbo].[Blogs] ([Name], [Url])
  VALUES (@Name, @Url)


The update and delete procedures will be ab shown below

CREATE PROCEDURE [dbo].[Blog_Update]
  @BlogId int,
  @Name varchar(max),
  @Url varchar(max)
  UPDATE [dbo].[Blogs]   SET [Name] = @Name, [Url] = @Url   
  WHERE BlogId = @BlogId;

CREATE PROCEDURE [dbo].[Blog_Delete]
  @BlogId int
  DELETE FROM [dbo].[Blogs]
  WHERE BlogId = @BlogId

The official documentation examines all the possible scenarios in detail.

Entity Framework 6 Alpha 3 includes connection resiliency that enables automatic recovery from transient connection failures. It is implemented using IExecutionStrategy interface which in turn make use of IRetriableExceptionDetector and IRetryDelayStrategy interfaces.

According to official sources, Entity Framework will ship with four execution strategies such as NonRetryingExecutionStrategy, DefaultSqlExecutionStrategy, ExecutionStrategy and SqlAzureExecutionStrategy.

Entity Framework 6 Alpha 3 provides an ability to pull request from iceclow that allows you to create custom migrations operations and process them in a custom migrations SQL generator. Rowan Miller, Program Manager, ADO.NET Entity Framework, Microsoft has examined the implementation of iceclow with relevant code samples.

The Alpha 3 also enables you to pull request from UnaiZorrilla which provides a pluggable pluralization and singularization service including the ability to manage your own transactions with the help of DbContext.Database.UseTransaction and DbContext.Database.BeginTransaction APIs.

Rate this Article