Creating a new Dynamic Data Web Application

I’m cleaning up my machine and found this material that I never posted to my blog.  It’s a bit old news, but still, I want to post it.

Overview

In this post we are going to create a dynamic data web application by doing the following:

  1. Create a new Dynamic Data Web Application
  2. Create a data model
  3. Register the data model and enable scaffolding
  4. Run the web application

Create a new Dynamic Data Web Application

  1. Open Visual Studio 2008
  2. Create a new Dynamic Data Web Application
    (a. File -> New -> New Project)
    clip_image002
  3. A new solution and project is created
    clip_image004

Run the new web application

  1. Run the web site (Ctrl+F5)
  2. You should get an error stating “There are no accessible tables. Make sure that at least one data model is registered in Global.asax and scaffolding is enabled or implement custom pages.”
    clip_image006

The reason for this error is because our web site doesn’t have a data source. The error message is also very clear in what we should do: (1) Register at least one data model in Global.asax and (2) enable scaffolding.

Create a data model

In this example we’ll use LINQ to SQL to create our datamodel. To do this we need to add a new Ling-to-sql classes file and add tables to the model.

  1. Right-click on the project and choose Add -> New Item
  2. Create a new LINQ to SQL classes file
    clip_image008
  3. We now see the Object Relational Designer. Let’s add a couple of tables from the Adventureworks database.
    clip_image010

Register the data model and enable scaffolding

Now that we have a data model, we need to tell the website about it.

  1. Open the global.asax file
  2. Make changes to the RegisterRoutes procedure as per the comments in the code.
  3. Uncomment the line and register the context.
  4. Enable scaffolding by setting ScaffoldAllTables to true

The code should look like this:

model.RegisterContext(typeof(AdventureWorksDataContext), new ContextConfiguration() { ScaffoldAllTables = true });

Run the web site again

When we run the website again, we now see our site up and running

clip_image012

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s