Creating a Dynamic Data Web Site in ASP.NET 4.0

Steps to create a new ASP.NET Dynamic Application with Linq to SQL

Step 1. To create a new web application and application type will be using an ASP.Net Dynamic Data Linq to SQL Web Application.

SQL

Step 2. Now we'll add a database to the web application. I have added an MDF file in the App_data folder.

Data folder

Step 3. Now we'll add LINQ to SQL Classes.

 SQL Classes

Step 4. Now we will add the required tables in the DBML file.

 DBML file

Step 5. Now when you run your application you will get the following error.

Error

To resolve the error we need to make some changes in the Global. asax file.

By default, this line is commented.

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

we need to add our entity context there and ScaffoldAllTables should be true.

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

Step 6. Now when we run our application the output will be.

Application

You will see three tables in the above image. The Customer and Store tables can accept a null value for their columns. But the Employee Table will not accept a null value because we have added a null constraint to all columns.

Employee Table

The conclusion is that we can easily create Data Dynamic applications.


Similar Articles