January 28, 2010 12:00 AM

Using Dynamic Data in Visual Studio 2010

VS2010 Dynamic Data templates eliminate tedious coding in data-driven applications
DevConnections
Rating: (6)

Walk through the wizard accepting the defaults. Since I've added the database first, the wizard is smart enough to attach to it. Make the selections shown in Figure 5.

Also make sure that the name of the entity is KingOfPopModel; that will come in handy later. Click Finish. The infrastructure hook-up is complete. In Solution Explorer, open the Global.asax file. Find and uncomment the line similar to this:

 

DefaultModel.RegisterContext(typeof(YourDataContextType), new ContextConfiguration() { ScaffoldAllTables = false });

 To enable dynamic data to work with the new model, set the ScaffoldAllTables to true. You'll need to scaffold at least one table otherwise a run-time exception will be thrown. Also, pass in the entity model to the RegisterContext method. That will register and expose the context object to the code so that I can work with strongly typed domain objects. The completed code looks like this:

 

DefaultModel.RegisterContext(typeof(KingOfPopEntities), new ContextConfiguration() { ScaffoldAllTables = true });

 Press F5 to run the application, see Figure 6.

The web application is production ready. The application can:

  • Page, sort, insert, and delete data.
  • Select and edit item data.
  • Provide a detail view for selected data.
  • Adjust the size of data in the page.
  • Confirm entity delete operations.
  • Validate against the entity model.

All that functionality came for free; I did not have to write any code, well one line to be exact. Much of the magic driving this application is based on the intimate knowledge that the entity model has of the data store. The model can translate domain concepts into efficient database queries.

Dynamic data also supports AJAX. I can quickly add AJAX support by setting the EnablePartialRendering method of the ScriptManager object to true. The ScriptManager object is located in the site.master master page.

Dynamic data does most of the heavy lifting using templates. Templates can be customized, modified, and extended to create powerful data-driven applications. These applications can be built and deployed in the time it takes to finish off that morning coffee. You can even inject Dynamic Data infrastructure into ordinary web projects!  In the next article, I'll walk you through complex validations and customizations so that you can make your web applications sing!

Alvin Bruney is a longtime Microsoft MVP and author. His new book, ASP.NET 4 by Example is available on www.lulu.com/owc.

Add a Comment

There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement




Comments from the DevConnections Community

Join our community of development pros.

Windows problem

I all, I have a problem on my Windows Vista that began afetr the purchase of an external Hard Disk Freecom. A few days afetr the purchase I discon...

Most Recent Posts

GOOGLE LINKS
SPONSORED LINKS
FEATURED LINKS