New ASP.NET Dynamic Data Support

The ASP.NET 3.5 Extensions CTP we shipped this past weekend contains a bunch of great new features.

One of the cool new features is something we call "ASP.NET Dynamic Data Support".  In a nutshell this enables you to really quickly build data driven web-sites that work against a LINQ to SQL (and in the future LINQ to Entities) object model - and optionally allows you to-do this without having to build any pages manually.

The best way to see this in action is to watch David Ebbo's awesome 17 minute screen-cast:

You can also follow the steps below to easily get started and use the dynamic data support:

Step 1: Create a ASP.NET Dynamic Data Site:

Once you have the ASP.NET 3.5 Extensions CTP release installed, you can use VS 2008 or the free Visual Web Developer 2008 Express to create a new Web Site or Web Application Project that has the ASP.NET dynamic data support enabled:

This will create a new web-site you can use that has some default template files in them, along with CSS style-sheets you can use to customize the look and feel of them:

Step 2: Add a LINQ to SQL Data Model to Your Site

LINQ to SQL is an O/RM (object relational mapper) that ships in .NET 3.5, and which allows you to model a relational database using .NET classes.  You can then query the database using LINQ, as well as update/insert/delete data from it.  LINQ to SQL fully supports transactions, views, and stored procedures.  It also provides an easy way to integrate data validation and business logic rules into your data model.

The easiest way to get started with an ASP.NET Dynamic Data site is to add a new LINQ to SQL data model to your project (right-click->add new item->LINQ to SQL Classes item).  This will bring up the LINQ to SQL class designer.  Drag database tables from your server explorer to define a set of classes (with relationships) for your database schema:

Step 3: Enable Dynamic Templates in Your Project:

By default ASP.NET Dynamic Data projects provide built-in support for creating automatic "scaffolding" views of your LINQ to SQL and LINQ to Entities data models.  Dynamic Data projects include template pages and user controls that can automatically create built-in data browsing/editing/selection/deleting UI that is dynamically constructed at runtime based on the LINQ to SQL or LINQ to Entities data model you've added to your project.

To enable this auto-scaffolding support, open the web.config file of your project, search for the "dynamicData" section within it, and set the "enableTemplates" attribute to "true":

Note: this auto-scaffolding feature is currently turned off by default for security reasons (we want you to be explicit about turning it on). 

Note: as you can see above, the ASP.NET dynamic data section provides optional URL mapping support that allows you to customize the URLs for your dynamic scaffold pages to be in whatever URL format you want.

Step 4: Run Your Site

Hit F5 to run your project.  You'll by default be taken to a default.aspx page that lists all of the table objects in your data model:

Note: the default.aspx home-page is in the project - if you don't like how it looks just open it up and edit it however you want.

Clicking on any of the table names in the list above will take you to a dynamic data page that lists the data within it:

The default data view pages automatically create functional data navigation UI that includes built-in data paging and editing support (and are ASP.NET AJAX enabled):

The data view pages automatically infer relationships between your related objects and provide automatic filtering support:

The data view pages also automatically show relationships between your objects and allow users to easily navigate amongst them.  For example, notice how the Category column for products allows me to navigate to the category details for a specific product:

The data view pages also enable automatic selection, editing and delete support.  Notice below how when in inline edit mode they automatically infer friendly foreign key names (allowing you to edit the "Category" and pick a name from a dropdownlist instead of having to specify a "CategoryID" integer):

All of this works without having to create a single custom .aspx page or write any custom code.  All of the web UI is created dynamically off of your LINQ to SQL or LINQ to Entities data model.

Step 5: Customizing the Site Further

Having all of the above functionality work out of the box against your ORM data model is great for quickly getting your site up and running.  Once you get the basic site experience working, you can optionally go in and fully customize it - both at the data validation/business logic level as well as at the UI layer.

You can add standard LINQ to SQL data model and business validation rules to your data model in order to enforce constraints.  The dynamic data pages will automatically work off of this logic, and provide appropriate error messages and validation UI based on them. 

You can also optionally go in and customize the UI of any of the data pages you want.  Dynamic data projects allow you to customize the default look and feel of all data pages on the site, as well as customize the default look and feel of all column types used on the site.  You can customize both of these via the default template files added under the "/App_Shared" folder when you create a new dynamic data project:

Simply edit any of the files above to customize the default data page views and/or default data column appearances. 

You can also then optionally override the UI of specific data view pages by explicitly adding a .aspx page that maps to it in your project.  For example, I could override the default ListDetails behavior for Products by adding a \Products\ListDetails.aspx page to my project:

You can then add any standard ASP.NET data control to the page.  You can also use the new dynamic data aware ASP.NET data controls that ship in the ASP.NET 3.5 Extensions CTP to the page.  These allow you to completely customize the look and feel of the UI - while still using the new dynamic meta-data provider to infer relationships and meta-data about your data model classes for default behavior.

Learning More

The above walk-through only touches on a few of the scenarios and capabilities you can enable with ASP.NET Dynamic Data Projects.  To learn more:

  1. Watch David's webcast
  2. Check out the ASP.NET Dynamic Data QuickStarts
  3. Subscribe to David Ebbo's, Scott Hunter's, and Marcin Dobosz's blogs
  4. Visit the ASP.NET Dynamic Data Forum to ask questions

To learn more about LINQ to SQL and how you can use it to create data model classes, also check out my previous blog posts below:

You can also watch the great LINQ and LINQ to SQL "How do I?" videos on the www.asp.net site here.

Hope this helps,

Scott

Published Friday, December 14, 2007 12:41 AM by ScottGu
Filed under: , , ,

Comments

# re: New ASP.NET Dynamic Data Support

Friday, December 14, 2007 4:18 AM by Gill Cleeren

I think the controls have a great functionality. However, I don't really see me using them in large scale business applications that require specific handling and displaying of data. Maybe I'm seeing this incorrectly?

# re: New ASP.NET Dynamic Data Support

Friday, December 14, 2007 4:49 AM by Tom Vanassche

Good article, I've been digging into the latest ASP.NET version for work, and these articles are really helpful!

# re: New ASP.NET Dynamic Data Support

Friday, December 14, 2007 4:53 AM by Mike Lockyer

Very interesting and very flexible but I have a problem with so much DB field/table information being linked via strings. eg when adding a validation attribute and RenderHint attribute and DisplayColumn and DataField shown later in the screencast

I believe that we should be moving away from and such string links between UI and DB because of the difficulty of maintaining such a system when the db changes as only subsequent errors would only show up at run-time

Mike

# re: New ASP.NET Dynamic Data Support

Friday, December 14, 2007 5:00 AM by milkbb

It's great! You always help. Thanks.

沙发

# re: New ASP.NET Dynamic Data Support

Friday, December 14, 2007 5:29 AM by Jonty

Is it possible to create a new instance of the database from the .dbml file?

# re: New ASP.NET Dynamic Data Support

Friday, December 14, 2007 5:30 AM by Rodrigo

Very nice post scott.. Is there some way of using this with the MVC

framework?

# re: New ASP.NET Dynamic Data Support

Friday, December 14, 2007 5:41 AM by Ali

Another good work from Microsoft team.

keep it up

Ali Zaidi

ali.zaidi@plexuspk.com

# re: New ASP.NET Dynamic Data Support

Friday, December 14, 2007 6:17 AM by David Dahlem

Hi Scott,

It would be nice if I could selectively enable only certain parts of my existing Web site to be dynamically generated.  For example, I may decide that it is beneficial to replace the content within my "products" and "services" sub-folders with dynamically generated data.  Here are my questions:

1. Is it currently possible (or in the plans to make it possible) to infuse 'dynamic data' support into existing Web projects?  Or will we always need to start with the "Dynamic Data Website" project template, and thus we'll need to maintain separate Web sites for 'dynamic' and 'non-dynamic' content?

2. Is it possible (or do you plan to make it possible in the future) to specify multiple 'dynamicData' web.config sections so that dynamic data can be generated from multiple linq datacontexts and/or so that we can define multiple 'mappings' patterns, e.g., pattern="~/products/{table}/{viewName}.aspx" and pattern="~/services/{table}/{viewName}.aspx"

# re: New ASP.NET Dynamic Data Support

Friday, December 14, 2007 6:24 AM by Paul

Scott, great stuff!  I'm curious, though, why the MVC framework seems to do all URL mapping in the globabl.asax, while the Dynamic Data extensions do it in the web.config?  Is there any plan in the future to make it such that they can both choose to do it either way (e.g. simple mappings w/ default route handers can go in the web.config, more custom stuff goes in the global.asax)?  

Thanks,

Paul

# re: New ASP.NET Dynamic Data Support

Friday, December 14, 2007 7:34 AM by John Chapman

Scott,

Just for clarification, is Microsoft recommending this as a mechanism to build production web sites?  Or is this intended to allow teams to put together prototypes or proof-of-concept applications quickly to help obtain the funds needed to produce the final production web site?  I realize a user would always be free to use it however they wanted, but what would Microsoft's recommendation be?  This seems potentially dangerous for production applications.

# re: New ASP.NET Dynamic Data Support

Friday, December 14, 2007 7:57 AM by Robert Mao

Dynamic Data is really nice, I am wondering how to integrate the Dynamic Data together with ASP.NET MVC, I saw such a demo (oryxMVC) from the other Scott's blog however there is no more information other than the source code.

# re: New ASP.NET Dynamic Data Support

Friday, December 14, 2007 8:42 AM by Mark Wisecarver

Ooooo kudos for Step 5.

# re: New ASP.NET Dynamic Data Support

Friday, December 14, 2007 8:55 AM by elias_bland

Hi there, this is all great stuff, how can we use it with the MVC framework? Could you point us to any walkthroughs or examples that might give me a pointer.

Thanks!

# re: New ASP.NET Dynamic Data Support

Friday, December 14, 2007 10:33 AM by Matt

Any update on offering a LINQ to Oracle provider?

# re: New ASP.NET Dynamic Data Support

Friday, December 14, 2007 11:02 AM by Catto

Hey Now Scott,

This content just keeps getting better & better.

Thx 4 the info,

Catto

# re: New ASP.NET Dynamic Data Support

Friday, December 14, 2007 11:10 AM by Steve

That project icon is awesome. Vintage 1993. :-)

# re: New ASP.NET Dynamic Data Support

Friday, December 14, 2007 11:30 AM by Dan

This is really cool stuff. In alot of the corporate apps I can use this to eliminate about 30-40% of the admin type screens we build. Nice work!

# re: New ASP.NET Dynamic Data Support

Friday, December 14, 2007 12:41 PM by Nisim Borukhov

I wish I can be like Scott

# re: New ASP.NET Dynamic Data Support

Friday, December 14, 2007 12:59 PM by Rupak Ganguly

sheer fun. David's screencast was a beauty. ms may come a bit late but they come hard! Kudos Scott to you and your team. And, by the way, hiring Rob Conery was a great move. Subsonic needs to be in the next MVC bits.

# re: New ASP.NET Dynamic Data Support

Friday, December 14, 2007 3:49 PM by The big B

Leave subsonic out of it!

# re: New ASP.NET Dynamic Data Support

Friday, December 14, 2007 4:15 PM by Patty

I think all this stuff is great but at the same time useless for large scale business apps. Using strings to connect data. Building the objects using LINQ to SQL.

What you should be doing is building a true multi-tier Business Object generator that puts mygeneration, llblgen, etc to SHAME by integrating with VS, suppports business rules, etc and allowing developers to customize and extend how the business objects themselves are generated, etc.

Instead it seems the priority is building functionality so that all those useless beginner books just let users get that much more data to the screen that much faster and direct bypassing everything else that ones learns about building good large scale applications.

# re: New ASP.NET Dynamic Data Support

Friday, December 14, 2007 10:22 PM by Sambo

Thank for your good post.

# re: New ASP.NET Dynamic Data Support

Friday, December 14, 2007 11:01 PM by vikram

Wow that a quick way to create a fast web site. But Dont think that much useful in a bigger scale application

# re: New ASP.NET Dynamic Data Support

Saturday, December 15, 2007 6:47 AM by John

Does visual studio 2008 (ASP.net) allow a way to build a multi-tab layout?  Almost to mimic something that would appear in a Windows VB application?  

Thanks,

John

# re: New ASP.NET Dynamic Data Support

Saturday, December 15, 2007 9:35 AM by Mani

The new VS2008 is really slow and sucks. Generally this IDE makes programming slower! I call it SDE. stupid development environment. I am more productive in a good editor like vi.

I wonder is any body in microsoft cares for performance? I have both Windows Vista and Visual Studio 2005 and 2008 on my laptop. and I must say from performance point of view, Microsoft technologies are only good for Hardware Companies like Intel to sell their new CPUs.

I don't need flash and lots of never use features, I only want to build my solution fast.

# re: New ASP.NET Dynamic Data Support

Saturday, December 15, 2007 10:55 AM by Rida

Great Work, keep going Scott

# re: New ASP.NET Dynamic Data Support

Sunday, December 16, 2007 11:07 AM by Paul

@Jonathan Holland

Thanks for the link.  I was less worried about rolling a module for it, and more curious about their design process / decisions.  i.e. what was their thinking on why they implemented it in different ways in two (potentially related) libraries.

# re: New ASP.NET Dynamic Data Support

Sunday, December 16, 2007 11:43 PM by sSixYo

Microsoft MVC is so cool ...

# re: New ASP.NET Dynamic Data Support

Monday, December 17, 2007 6:23 AM by Deepak Chawla

Is this a wrapper over BLINQ by Polita.

I remember I saw similar on ASP.NET ages ago.

# re: New ASP.NET Dynamic Data Support

Tuesday, December 18, 2007 3:34 AM by ScottGu

Hi Everyone,

David Ebbo posted a great follow-up post that answers many of the question above (MVC support, URL routing configuration, etc).  You can read his post here: blogs.msdn.com/.../answers-to-frequently-asked-asp-net-dynamic-data-questions.aspx

Hope this helps,

Scott

# re: New ASP.NET Dynamic Data Support

Tuesday, December 18, 2007 3:37 AM by ScottGu

Hi Jonty,

>>>>>>> Is it possible to create a new instance of the database from the .dbml file?

Yes - the DataContext class with LINQ to SQL (which is what is generated from the .dbml file) has a "CreateDatabase()" method.  Simply point at a database and call that method and it will create a database for you based on it.

Hope this helps,

Scott

# re: New ASP.NET Dynamic Data Support

Tuesday, December 18, 2007 3:41 AM by ScottGu

Hi John,

>>>>>>> Does visual studio 2008 (ASP.net) allow a way to build a multi-tab layout?  Almost to mimic something that would appear in a Windows VB application?  

Yes - you can use the tab-control in the ASP.NET AJAX Control Toolkit to achieve this.  Here is a pointer to it: www.asp.net/.../samples

Hope this helps,

Scott

# re: New ASP.NET Dynamic Data Support

Tuesday, December 18, 2007 3:43 AM by ScottGu

Hi Mani,

>>>>>>>> The new VS2008 is really slow and sucks. Generally this IDE makes programming slower! I call it SDE. stupid development environment. I am more productive in a good editor like vi.

If you are finding VS 2008 slower than VS 2005, then it is most likely because of some configuration error (either with VS or with your application).  Pretty much every scenario with VS 2008 should be faster than VS 2005.  If you want to send me an email (scottgu@microsoft.com) with the specifics of the slowness issue you are seeing we can take a look to figure out what is wrong.

Thanks,

Scott

# re: New ASP.NET Dynamic Data Support

Tuesday, December 18, 2007 3:44 AM by ScottGu

Hi Matt,

>>>>>>>> Any update on offering a LINQ to Oracle provider?

I believe one is coming out with LINQ to Entities next year.  Hopefully not too long now.

Thanks,

Scott

# re: New ASP.NET Dynamic Data Support

Tuesday, December 18, 2007 3:45 AM by ScottGu

Hi Portman,

>>>>>>>> What's the recommended place to provide feedback on Dynamic Data? Your blog? David's blog? ASP.NET forums? Having build my own [far inferior] implementation of DynData back in the consulting days, I have several of suggestions and questions for the team.

David's blog or the dynamic data forum on www.asp.net is probably the best way to leave feedback - since that way it goes straight to the team.  It would be awesome if you could share your experiences with them.

Thanks,

Scott

# re: New ASP.NET Dynamic Data Support

Tuesday, December 18, 2007 4:16 AM by tom.vangaever

nice,

how do they auto implement the LINQ datacontext?

Tom

# re: New ASP.NET Dynamic Data Support

Tuesday, December 18, 2007 10:30 AM by anytao

It's a wonder feature, I just use this template in my project. 3x.

# re: New ASP.NET Dynamic Data Support

Tuesday, December 18, 2007 4:38 PM by jeff

Scott,

I tried joining the ASP.NET forums, but had problems so perhaps you could help me.  I have some join tables in my database that contain only integer columns.  The Dynamic Data framework does not like these.  It tries to convert the int64 to a string and bombs out.

It dies on line 6 of ForeignKey.ascx with an InvalidCastException.  

   protected string GetDisplayString() {

       DynamicMetaForeignKeyMember column = (DynamicMetaForeignKeyMember)MetaMember;

       return FormatDataValue(column.OtherMetaTable.GetDisplayString(DataValue));

   }

System.InvalidCastException was unhandled by user code

 Message="Unable to cast object of type 'System.Int64' to type 'System.String'."

 Source="System.Web.Extensions"

 StackTrace:

      at System.Web.DynamicData.DynamicMetaTable.GetDisplayString(Object value)

      at ASP.app_shared_dynamicdatafields_foreignkey_ascx.GetDisplayString() in c:\Projects\test\WebSite1\App_Shared\DynamicDataFields\ForeignKey.ascx:line 6

      at ASP.app_shared_dynamicdatafields_foreignkey_ascx.__DataBindingHyperLink1(Object sender, EventArgs e) in c:\Projects\test\WebSite1\App_Shared\DynamicDataFields\ForeignKey.ascx:line 10

      at System.Web.UI.Control.OnDataBinding(EventArgs e)

      at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)

      at System.Web.UI.Control.DataBind()

      at System.Web.UI.Control.DataBindChildren()

It seems to me that the call to column.OtherMetaTable.GetDisplayString(DataValue) should know how to handle long integers.

thanks,

--Jeff

# re: New ASP.NET Dynamic Data Support

Wednesday, December 19, 2007 3:37 AM by S. Jorgensen

My wish for this christmas is a "print article" functionality on this forum...

# re: New ASP.NET Dynamic Data Support

Wednesday, December 19, 2007 5:24 PM by kemaltolga

Scott, this is really excited. I am having issues when deploying a website of type "dynamic data website" to a production server. I did install .net 3.5 Extension, so the page renders ok (the home page). However, when "clicking" on any of my table links, I get a "Resource not found" error messge. Any ideas?

thanks

--t

# re: New ASP.NET Dynamic Data Support

Friday, December 28, 2007 2:20 PM by LukCAD

Happy New Year Scott!

Thank you, it is good explanation about main feature of the ASP.NET 3.5 Extensions! Really, it will speed up the developing process of new applications.

Sincerely, LukCAD

# re: New ASP.NET Dynamic Data Support

Sunday, January 6, 2008 10:31 AM by Sam MacDonald

Scott - I can see this tool as being a great way to get a quick admin section setup for sites.

# re: New ASP.NET Dynamic Data Support

Friday, January 11, 2008 11:44 AM by Mohamed Faramawi

This reminds me with what Ruby on Rails do,but i'm happy we can do this on ASP.NET, basically this will require alot of customization to fit big business websites, but for basic work or testing matters, this is just great.

# re: New ASP.NET Dynamic Data Support

Saturday, January 12, 2008 12:47 PM by RdRunnerxx

Scott,

I find Dynamic Data Control to be the poor man's way of creating "quick&dirty" web pages in order to display data. This is for the boys only. Real men will never use DDCs. In this day and age users are demanding state-of-the-art and slick user-interfaces.  I will probably use DDC for testing but patiently wait for the next version of ASP.NET Futures with some real data controls.

# re: New ASP.NET Dynamic Data Support

Sunday, January 27, 2008 9:59 PM by Jesse

Dynamic Data Websites are great!  It is the customization ability that makes them extremely useful.  I look forward to the next release.

# re: New ASP.NET Dynamic Data Support

Sunday, February 3, 2008 6:30 AM by mr_maxmaxmax

How the Dynamic Data support for File fields like picture or attachment?