Search This Blog

Sunday, March 16, 2014

Dynamic Data Provider(DDP) and EntityDataSource Control for EF6



Dynamic Data Provider(DDP) and EntityDataSource 

Control for Entity Framework 6


Microsoft has announced an update to ASP.NET DynamicData and EntityDataSource control, so that they work with Entity Framework 6.


How to install this preview

You can download this preview for ASP.NET DynamicData.EFProvider (http://www.nuget.org/packages/Microsoft.AspNet.DynamicData.EFProvider/) and EntityDataSource (http://www.nuget.org/packages/Microsoft.AspNet.EntityDataSource/) as preview NuGet packages from the NuGet gallery. You can install these pre-release packages through NuGet using the NuGet Package Manager Console, like this:
  • Install-Package Microsoft.AspNet.DynamicData.EFProvider -Version 6.0.0-alpha1 –Pre
  • Install-Package Microsoft.AspNet.EntityDataSource -Version 6.0.0-alpha1 –Pre

Microsoft.AspNet.DynamicData.EFProvider

This package has a DynamicData EFProvider for Entity Framework 6. This provider can work with a Model (either Code First or EF Designer) which was created using Entity Framework 6. This package also installs the Page Templates, Entity Templates and Field Templates which are required for DynamicData. The templates have been updated to useMicrosoft.AspNet.EntityDataSource control which we are also previewing today as well.
Following are the steps for using this package in a ASP.NET DynamicData application:
  1. Create a new ASP.NET Dynamic Data Entities Web Application
  2. Add the Microsoft.AspNet.DynamicData.EFProvider NuGet package
  3. This will do the following
    1. Add a reference to the DynamicData EFProvider binary
    2. Install the templates. If you are starting with a new project, then you can override the templates. If you have an existing application, then you should be careful when overriding the changes. The templates replace the EntityDataSource control which shipped in .NET with Microsoft.AspNet.EntityDataSource and also have a few bug fixes in the Many-Many field template so they work with Entity Framework 6.
  4. Create your model using Entity Framework Code First or EF Designer.
  5. Add the following code in RegisterRoutes in Global.asax.cs to register your EF Model:
    DefaultModel.RegisterContext(
        new Microsoft.AspNet.DynamicData.ModelProviders.EFDataModelProvider(
            () => newNorthwindEntities1()),
        newContextConfiguration { ScaffoldAllTables = true });
  6. Run the project
  7. You would see all the tables listed on the Default page.

Microsoft.AspNet.EntityDataSource Control

This is an update to the EntityDataSource control which shipped in the .NET Framework. The EntityDataSource control has been updated to work with Entity Framework 6.
To use this control, please do the following
  1. Create an ASP.NET application
  2. Install the package Microsoft.AspNet.EntityDataSource
    1. This package will
      1. install the runtime binary for Microsoft.AspNet.EntityDataSource
      2. Install the EntityFramework version 6 NuGet package
      3. Add the following tag prefix in web.config
         
           
                  tagPrefix="ef" 
              assembly="Microsoft.AspNet.EntityDataSource" 
              namespace="Microsoft.AspNet.EntityDataSource" /> 
           
         
  3. Create a new Web Form page
  4. Use the control as follows and bind it to any Databound control such as GridView, FormView etc.
     

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 and will not work for WebSites projects.

No comments:

Post a Comment