BT

New Early adopter or innovator? InfoQ has been working on some new features for you. Learn more

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

| by Anand Narayanaswamy on Mar 01, 2013. Estimated reading time: 1 minute |

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)
AS
  INSERT INTO [dbo].[Blogs] ([Name], [Url])
  VALUES (@Name, @Url)

  SELECT SCOPE_IDENTITY() AS BlogId

The update and delete procedures will be ab shown below

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



CREATE PROCEDURE [dbo].[Blog_Delete]
  @BlogId int
AS
  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

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Entity Framework is Excellent! by Kinect Dev

I'm excited to try these new features out. EF's support for LINQ makes it the preferred ORM for .Net development. If I could request any two features I would request:

1) Better multi-threaded support (i.e. deeper support for async/await)
2) Support for WinRT (i.e. metro or Windows Store Apps) against a local, embedded DB.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

1 Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and dont miss out on content that matters to you

BT