Dynamic Data Entities Websites - EntityDataSource and ASP.NET Website Scaffolding - Rapid Application Development ( RAD )

If you check out my ASP.NET Dynamic Data Tutorials, we have essentially been focusing on ASP.NET Dynamic Data and LINQ To SQL. The reason being that ASP.NET Dynamic Data has been using the LinqDataSource and there has been no such thing as an EntityDataSource. Well, now with Visual Studio 2008 SP1 we have a new EntityDataSource and hence a couple of different options now for generating ASP.NET Dynamic Data ( Scaffolding ) Projects:

  • Dynamic Data Web Applications / Websites - Uses LinqDataSource and LINQ To Sql
  • Dynamic Data Entities Web Applications / Websites - Uses EntityDataSource and ADO.NET Entity Data Model

Not sure what has happended to the previous ASP.NET Dynamic Data Wizard, but maybe it will show itself at some point before the official release of Visual Studio 2008 SP1 or be a separate add-on.

 

Dynamic Data Websites

 

Dynamic Data Entities ASP.NET Web Applications / Websites

Although the name implies the use of the ADO.NET Entity Framework, at first I didn't see any difference between the two different types of ASP.NET Dynamic Data Projects. However, when you look at the templates pages we see that the Entities Version of Dynamic Data uses the new EntityDataSource as opposed to LinqDataSource:

 

<asp:EntityDataSource ID="GridDataSource"
        runat="server" EnableDelete="true">
    <WhereParameters>
        <asp:DynamicControlParameter
                ControlID="FilterRepeater" />
    </WhereParameters>
</asp:EntityDataSource>

 

Again, what we are used to seeing in the past is the LinqDataSource, which is still used in the Dynamic Data Web Application Project Type:

 

<asp:LinqDataSource ID="GridDataSource"
        runat="server" EnableDelete="true">
    <WhereParameters>
        <asp:DynamicControlParameter
            ControlID="FilterRepeater" />
    </WhereParameters>
</asp:LinqDataSource>

 

Basically just pick your O/R Mapper of choice for your application - LINQ To SQL or the ADO.NET Entity Framework.

 

ADO.NET Entity Data Model and ASP.NET Dynamic Data

To get the ASP.NET Dynamic Data Entities Websites Project to work you need to of course add an ADO.NET Data Model to your application. I am going to assume you know how to do it. Adding an ADO.NET Entity Data Model to your ASP.NET Web Application is as simple as it gets. Just choose "Add New Item..." from your ASP.NET Web Application and pick the ADO.NET Entity Data Model. A wizard walks you through the creation of the model. I typically choose the Northwind Database for all my samples.

 

Entity Data Model

 

EntityDataSource Tutorial

 

EntityDataSource Example

 

ASP.NET Dynamic Data Websites Global.asax

Once you have the ADO.NET Data Model added to the Dynamic Data Entities Website, you need to go into your Global.asax file or its codebehind and wire up the NorthwindEntities as your Entity Data Model. Make sure to set Scaffolding = true so that Dynamic Data discovers and displays the entities for you:

 

public static void RegisterRoutes(RouteCollection routes)
{
    MetaModel model = new MetaModel();
    
    model.RegisterContext(typeof(NorthwindEntities),
        new ContextConfiguration() { ScaffoldAllTables = true });

    routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx")
    {
        Action = PageAction.List,
        ViewName = "ListDetails",
        Model = model
    });

    routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx")
    {
        Action = PageAction.Details,
        ViewName = "ListDetails",
        Model = model
    });
}

 

ASP.NET Dynamic Data Entities Websites in Action

From there just run the Dynamic Data Web Application and be impressed by its use of the EntityDataSource and ADO.NET Entity Data Model as well as its Scaffolding:

 

Dynamic Data Web Applications

 

 

Conclusion

Make sure you check out the new ASP.NET Dynamic Data Entities Support in the Visual Studio 2008 SP1 as well as the new EntityDataSource Control for building RAD ASP.NET Websites. For more information on the new EntityDataSource, check out: EntityDataSource Companion to ADO.NET Entity Data Model in Visual Studio 2008 SP1. ASP.NET Dynamic Data is changing a lot, but hopefully some of my previous ASP.NET Dynamic Data Tutorials may still be of help.

 

Hope this helps,

David Hayden

 

posted on Tuesday, May 13, 2008 10:41 AM

Main

News

Green Tea

.NET Development

Enterprise Library

Patterns & Practices