The easiest way to start with ASP.NET 3.5 Dynamic Data

This post is meant to introduce you to one of the six new features that are coming with ASP.NET Extensions. You can find an introduction post about extensions here.

Step 1: Get the machine ready

Be sure you have already installed Visual Studio 2008 (any version) or Visual Web Developer 2008 Express Edition. Also it is mandatory to install any SQL Server 2000, 2005, 2008 version.

Download and install ASP.NET 3.5 extensions preview. (3.6 MB)

Download and install .NET 3.5 enhancements training kit. (34.9 MB)

After you have installed the training kit, go to the folder you have installed it, and look for the setup folder into the AspNetDynamicData Labs; in my case C:\NETFramework35Enhancements_TrainingKit\Labs\AspNetDynamicData\Setup.

There you will find the file Lab_CreateDatabase.sql. Execute it from a SQL Server Console to create the data model used in this example.

Step 2: Create a Dynamic Data application project

  1. Open Microsoft Visual Studio 2008 from Start | All Programs | Microsoft Visual Studio 2008 | Microsoft Visual Studio 2008.

  2. On the File menu, point to New Project.

  3. In the New Project dialog box select Visual C# | Web. Make sure that .NET Framework 3.5 is selected and select the Dynamic Data Web Application project type. You may set the name to AspNetDynamicData and the location to AspNetDynamicData\Ex01-CreatingDynamicDataApp\begin which is the provided folder.

  4. Click OK to create the application project.

 

Step 3: Adding the database to the project

In this task you will add a new connection to the AdventureWorks database, so then you can create classes to represent database entities by using LINQ to SQL classes.

  1. Add a new database connection in the Server Explorer. To do this, in Server Explorer, right-click Data Connections and click Add Connection. (to display Server Explorer if it is not being shown, press Ctrl + Alt + S)

 

  1. In the Add Connection dialog window, enter the name of your SQL Server instance as Server Name, then select AdventureWorksLT database and click OK.

Step 4: Create the database model

In this task you will create the database model using LINQ to SQL classes; Visual Studio will persist out .NET classes that represent the entities and the database relationships modeled.

  1. Add an App_Code folder in the case that the Web site does not already have one. To do this, in Solution Explorer, right-click the project, point to Add New Folder, and then type App_Code.

 

  1. Add the LINQ to SQL class that will represent the database model. To do this, right-click the App_Code folder and then click Add New Item. On the Add New Item dialog, click on LINQ to SQL Classes. Type AdventureWorks.dbml in the Name textbox and click Add.

 

  1. Add some database tables to the AdventureWorks LINQ to SQL class. To do this, in Server Explorer, expand the AdventureWorksLT connection node you have added in the previous task, and expand the Tables node by clicking on the + (plus sign) next to each node. Drag the following tables into the Object Relational Designer:

Product(SalesLT)

ProductCategory(SalesLT)

ProductModel(SalesLT)

 

  1. Save the AdventureWorks.dbml file. To do this, press Ctrl + S. Note: If you open the AdventureWorks.designer.cs file, you will notice that it now has the AdventureWorksDataContext, Product, ProductCategory and ProductModel classes. The AdventureWorksDataContext class represents the database, and the Product, ProductCategory, and ProductModel classes represent database tables. The parameterless constructor of the AdventureWorksDataContext class reads the connection string from the Web.Config file. If you open the Web.Config file, you will notice that the connection string has been added in the connectionStrings element.

Step 5: Enabling scaffolding

  1. Enable automatic scaffolding feature in the Dynamic Data application. To do this, open the Web.config file and find the DynamicData section. Change the value of the enableTemplates property to true. Automatic scaffolding is not enabled by default for security reasons, because you are exposing all the tables in the data model for display and edit operations.

<dynamicData dataContextType="" enableTemplates="true">

  1. Save and close the Web.config file.

Now you can run the application and navigate your data model from the Default.aspx file and perform data operations. From this point you can also modify the scaffolding infrastructure to extend and personalize the web site.

Regards,

Carlos Figueroa - Quito, Ecuador

Published Friday, May 09, 2008 12:48 PM by Carlos Figueroa

Comments

# re: The easiest way to start with ASP.NET 3.5 Dynamic Data

Tuesday, May 13, 2008 7:56 PM by David Leon

Very nice job and much apreciated work.  Just curious to know:  You don't work for Seriva do you?  I might have run into you when I was just down in Quito a month ago.

Incidentally, my mom and dad were born in Quito.  I have 4 aunts and uncles and about 27 cousins down there.

# carlos figueroa

Thursday, May 15, 2008 3:10 AM by carlos figueroa

Pingback from  carlos figueroa

# re: The easiest way to start with ASP.NET 3.5 Dynamic Data

Thursday, May 15, 2008 3:02 PM by Carlos Figueroa

Hi David, how are you doing

I know Seriva fellows but I haven't worked for them... I used to work for Tata Consultancy Services (Banco Pichincha), but not anymore.

Even I am not from UIO I like this city, nice place to live!

Carlos

Leave a Comment

(required) 
(required) 
(optional)
(required)