Announcing the release of Dynamic Data provider and EntityDataSource control for Entity Framework 6

Announcing the release of Dynamic Data provider and EntityDataSource control for Entity Framework 6

Rate This
  • Comments 20

Today, we are pleased to announce RTM of ASP.NET Dynamic Data and EntityDataSource control for EntityFramework 6

What’s in this release

- Dynamic Data provider for Entity Framework 6

- EntityDataSource control for Entity Framework 6

How to install

You can download this release for ASP.NET DynamicData.EFProvider (http://www.nuget.org/packages/Microsoft.AspNet.DynamicData.EFProvider/) and EntityDataSource (http://www.nuget.org/packages/Microsoft.AspNet.EntityDataSource/) from the NuGet gallery.

  • Install-Package Microsoft.AspNet.DynamicData.EFProvider -Version 6.0.0
  • Install-Package Microsoft.AspNet.EntityDataSource -Version 6.0.0

Getting started

Microsoft.AspNet.DynamicData.EFProvider

This package has a DynamicData EFProvider for EntityFramework 6. This provider can work with a Model (either Code First or Model First) 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 use Microsoft.AspNet.EntityDataSource control which we are also previewing today as well.

For more information on ASP.NET DynamicData please see http://msdn.microsoft.com/en-us/library/cc488545.aspx

Following are the steps for using this package in a ASP.NET DynamicData application:

  • Create a new ASP.NET Dynamic Data Entities Web Application
  • Add the Microsoft.AspNet.DynamicData.EFProvider NuGet package
  • This will do the following
    • Add a reference to the DynamicData EFProvider binary
    • 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. These templates will replace the EntityDataSource control which shipped in .NET Framework with Microsoft.AspNet.EntityDataSource and the Page Templates, Field Templates, Entity Templates.
  • Create your model using Entity Framework Code First or EF Designer.
  • Add the following code in RegisterRoutes in Global.asax.cs to register your DbContext:
Code Snippet
  1. DefaultModel.RegisterContext(
  2. new Microsoft.AspNet.DynamicData.ModelProviders.EFDataModelProvider(() => new YourDbContext()),
  3. newContextConfiguration { ScaffoldAllTables = true });  
 
  • Run the project
  • 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

  • Create an ASP.NET application
  • Install the package Microsoft.AspNet.EntityDataSource
    • This package will
      • Install the runtime binary for Microsoft.AspNet.EntityDataSource
      • Install the EntityFramework version 6 NuGet package
      • Add the following tag prefix in web.config
Code Snippet
  1. <pages>
  2.   <controls>
  3.     <addtagPrefix="ef"assembly="Microsoft.AspNet.EntityDataSource"namespace="Microsoft.AspNet.EntityDataSource" />
  4.   </controls>
  5. </pages>
  • Create a new Web Form page
  • Use the control as follows and bind it to any Databound control such as GridView, FormView etc.
Code Snippet
  1. <asp:GridViewID="GridView1"runat="server"DataSourceID="GridDataSource"></asp:GridView>
  2. <ef:EntityDataSourceID="GridDataSource"runat="server"EnableDelete="true"/>

Give feedback

If you find any issues with this preview, please file issues at the EntityFramework CodePlex sitehttps://entityframework.codeplex.com

Thank you for trying out this release.

Leave a Comment
  • Please add 1 and 8 and type the answer here:
  • Post
  • Much required feature !

    Thanks

  • Just tested it, works like a charm, thanks

  • Did you test it with mapped views? It seems to work only for tables.

  • Sorry. Its works also for mapped views.

  • Any documentation/sample how to use EntityDataSource ?

    The code snippet above

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

    has no connection to EF data.

  • @Mike, you can use the EntityDataSource as you used it before. Following is a walkthrough of how to use EntityDataSource control www.asp.net/.../the-entity-framework-and-aspnet-getting-started-part-2

  • How about a quick note on how to add new Identity provider to enable Security on a dynamic data web app?

  • doh! Learned something new. IP restrictions on Azure websites. Allows me to use dynamic data deployed but restricted to IPs I work from. Cool.

    blogs.msdn.com/.../ip-and-domain-restrictions-for-windows-azure-web-sites.aspx

  • I tried adding it to an existing MVC site. It was a huge hassle and I eventually gave up. Decided to wait until support and documentation improved.

  • Thanks a lot , it will be very very useful!

  • I don't get it.  I've created lots of gridviews using EF in VS2010 and older versions of EF,  but I can't relate my EF model to this <ef:........../> line in VS2013.

    I installed the EF package and have EF dll, the SQL EF dll, and the EntityDataSource dll in my bin.  And my config has the ef tagPrefix

    My Model is ultra simple: a one table DB - table has 4 columns with 2 actual rows in it.

    I dragged a gridview onto a web form and added the <ef../> line and set the DataSourceID in the grid line:

           <asp:GridView ID="GridView1" DataSourceID="GridDataSource" runat="server"></asp:GridView>

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

    Going to the design pane doesn't work as you can't configure GridDataSource to tie it to a Model.  So, I started over and tried to configure an entity datasource before adding the <ef:...>  That doesn't work because you get the dreaded "unable to load the specified metadata resource" as soon as you select a named connection for the Model.

    I can do this same exercise with VS 2010 and the older EF and it works perfectly - Please explain the correct procedure - Thanks

  • @daveharney:  The code snippet provided in the blog post does not show all the properties that you need to set on the control to make it work, e.g. you need to do one of this:

    1. ContextTypeName to the name of a class derived from ObjectContext

    2. ConnectionString and the DefaultContainterName meEntitySetName

    3. Set the context instance in the ContextCreating event

    You will also need to either set the EntitySetName property (required for read-write scenarios) or the CommandText property to an Entity SQL query. Please refer to the EntityDataSource original documentation for more information:

    msdn.microsoft.com/.../system.web.ui.webcontrols.entitydatasource(v=vs.110).aspx

    msdn.microsoft.com/.../cc488502.aspx

  • Hi Diego,

    I'm sure your suggestion is completely correct but I won't be going down that path as this was not my expectation for what this control was going to do.  I thought it was going to restore the simple model we had before where you could create a model, drag a grid onto a form, and click through a smart tag dialog in the design page and then see your data displayed in the grid.  Also, I didn't notice any example in the links you provided that were specific to the use of this new control.  

    I already have a set of examples, for using EF6 in a more manual mode without this new control, that work just fine - what I miss is the quick method we had before.  For example, here is how I currently populate a grid in EF6:

    - download EF dlls

    - create model from DB

    <form id="form1" runat="server">

       <div>

           <asp:GridView ID="GridView1" runat="server" selectmethod="GridView1_GetData"></asp:GridView>

       </div>

    </form>

    Imports TinyDBEntities

    Imports System.Linq

    Partial Class _Default

       Inherits System.Web.UI.Page

       Public Function GridView1_GetData() As IQueryable

           Dim dbcontext As New TinyDBEntities()

           Return From myData In dbcontext.TestTables Select myData

       End Function

    End Class

    I have examples for all the other methods.  Is there some advantage to figuring out how to use this new control if I have to research your suggestions and fiddle with developing new examples?  Why didn't Microsoft just provide a compete example or tutorial for this new control?  I still don't understand this thing.

  • @daveharney: Thanks for the feedback on the lack of examples. I will pass this for consideration by the team. We haven't actually made any change to the control itself other than the necessary to make it work with the EF6 runtime. There is no designer wizard for the new version of the control but the markup you use is exactly the same you would have used with the previous version minus the asp prefix. The programmatic API is also the same. This basically means that most existing code examples for the EntityDataSource should continue to apply.

    The main two reasons to create the EF6 version of the EntityDataSource were to enable Dynamic Data features and to enable customers that wanted to move existing applications using EntityDataSource to EF6 more easily. If you are writing new code, Web Forms Model Binding can be a much better choice.

  • Hi Diego,

    OK, in case anyone else is interested, I created a gridview in VS2010 and ported it to VS2013 with the new control and it worked as you predicted.  So, it seems this is basically a migration tool.

    <body>

       <form id="form1" runat="server">

       <div>

         <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

           DataKeyNames="myKey" DataSourceID="EntityDataSource1">

           <Columns>

             <asp:BoundField DataField="myKey" HeaderText="myKey" ReadOnly="True"

               SortExpression="myKey" />

             <asp:BoundField DataField="FirstField" HeaderText="FirstField"

               SortExpression="FirstField" />

             <asp:BoundField DataField="SecondField" HeaderText="SecondField"

               SortExpression="SecondField" />

             <asp:BoundField DataField="comment" HeaderText="comment"

               SortExpression="comment" />

           </Columns>

         </asp:GridView>

    2.<ef:EntityDataSource ID="EntityDataSource1" runat="server" EnableDelete="true"

          ConnectionString="name=TinyDBEntities" DefaultContainerName="TinyDBEntities"

           EnableFlattening="False" EntitySetName="TestTables"

       />

    </div>

       </form>

    </body>

Page 1 of 2 (20 items) 12