Getting Started With Preview of Dynamic Data and Entity Data For EF 6

Introduction

Microsoft revealed an update to ASP.NET DynamicData and the EntityDataSource control this week. Now it works fine with the latest Entity Framework 6.

The following are the two main updates in this preview:

  • DynamicData provider for Entity Framework 6
  • EntityDataSource control for Entity Framework 6

Getting Started

You can easily download this preview update in the application by the following pre-release packages:

  • Install-Package Microsoft.AspNet.DynamicData.EFProvider -Pre
  • Install-Package Microsoft.AspNet.EntityDataSource -Pre

Microsoft.AspNet.DynamicData.EFProvider

As the name describes, the package have a DynamicData for the Entity Framework 6. Now you can use it with the Entity Data Model approache named Code First and Model First using Entity Framework 6. You can also benefit from the newly created Page Templates, Entity Templates and Field Templates and these are required for the Dynamic Data. These templates are also updated for the use of the Microsoft.AspNet.EntityDataSource control. Have a look at the following Solution Explorer screenshot:

Solution Explorer in Dynamic Site

Microsoft.AspNet.EntityDataSource

This is an update for the EntityDataSource Control that is now shipped in the .NET Framework. This control can now work with the latest Entity Framework 6.

Application Development

Now in the following procedure, we'll develop the application with the use of both updates defined above.

Step 1: Open Visual Studio and click on "New Project".

Step 2: Select the ASP.NET Dynamic Data Entities Web Application as shown below:

Creating Dynamic Data Application.

Step 3: Open the Package Manager Console and enter the following command:

Install-Package Microsoft.AspNet.DynamicData.EFProvider -Pre

This will add the new files and folders to the application and you can see them as defined in the Solution Explorer image.

Step 4: Now add the ADO.NET Entity Data Model by Code First or Model First approach

Step 5: Modify the RegisterRoutes() in the Global.asax file with the following highlighted code:

public static void RegisterRoutes(RouteCollection routes)

 {

      DefaultModel.RegisterContext(new Microsoft.AspNet.DynamicData.ModelProviders.EFDataModelProvider(

          () => new Cricketer_SiteEntities()),

          new ContextConfiguration { ScaffoldAllTables = true });

 

      // IMPORTANT: DATA MODEL REGISTRATION 

Step 6: Now install the following package (if it is not installed):

Install-Package Microsoft.AspNet.EntityDataSource -Pre

Step 7: Open the Web.Config file and add the following code to <system.web>:

<pages>

  <controls>

    <add tagPrefix="ef" assembly="Microsoft.AspNet.EntityDataSource" namespace="Microsoft.AspNet.EntityDataSource" />

  </controls>

</pages>

Step 8: Open the DynamicData\PageTemplates\List.aspx file and update the following code:

<asp:EntityDataSource ID="GridDataSource" runat="server" EnableDelete="true" />

To:

<ef:EntityDataSource ID="GridDataSource" runat="server" EnableDelete="true" />

Step 9: Now run the application and you can see that all the tables are listed on the default page:

Dynamic Data Site

That's it.

Known Issues

  • The templates in Microsoft.AspNet.DynamicData.EFProvider are for C# only.
  • The templates in Microsoft.AspNet.DynamicData.EFProvider are for Web Application projects only, not for Websites.

Summary

This article has described the new update preview of the Dynamic Data Provider and Entity Data Source for the Entity Framework 6. You can also learn how to develop the application with it. Thanks for reading and stay updated.

Up Next
    Ebook Download
    View all

    My Ideas

    Read by 1 people
    Download Now!
    Learn
    View all