Dynamic Data Entities Web Application

In this article, I will explain how to work with a Dynamic Data Entities Web Application which is available when a project is created.
 
In this article, I will show how to implement a CRUD operation without writing a single line of code and by just un-commenting a line in the Global.asax file.
 
The only thing you have to do is to add a reference in the Global.asax file with your project name you created. Since my project name is dynamicdataentities I will add this as a reference as follows:
  1. using dynamicdataentities; 
The only thing you have to do after this is to un-comment this line of code from the Global.asax file:
  1. DefaultModel.RegisterContext(typeof(YourDataContextType), new ContextConfiguration() { ScaffoldAllTables = false }); 
You have to replace this with the following:
  1. DefaultModel.RegisterContext(typeof(codeDBEntities), new ContextConfiguration() { ScaffoldAllTables = true }); 
Here codeDBEntities is nothing but the connection string which is available in the Web.config file or you can find it in Model.edmx.
 
First, let us create a project by selecting ASP.NET Dynamic Data Entities Web Application as follows:
 
Figure 1.jpg
 
This will create a project with a Master page, a Default page, and a Global.asax file along with script and CSS.
 
Now let us add an ADO.NET Entity Data Model as we did in our last article; see:
 
Figure 2.jpg
 
Figure 3.jpg
 
Since I already have a connection I am not showing how to add a connection; I will proceed with what I have.
 
Figure 4.jpg
 
Figure 5.jpg
 
Open the Global.asax file from the Solution Explorer:
 
Figure 6.jpg
 
You can find some code with comments, we will un-comment the one we need as follows:
 
Figure 7.jpg
 
Here in the place of YourDataContextType, you have to replace your context type which will be available in the web.config or Model.edmx:
 
Figure 8.jpg
 
Figure 9.jpg
 
Figure 10.jpg
 
Now run your application.
 
Figure 11.jpg
 
Since I integrated 2 tables it is showing those tables, select what is required to perform the CRUD operations.
 
I selected Employee and the details are as follows:
 
Figure 12.jpg
 
In the department dropdown you can determine the entire department listed, as follows:
 
Figure 13.jpg
 
If I select any then the corresponding details are shown as follows:
 
Figure 14.jpg
 
Inserting details into Employee table, if you select Insert New Item then it will display as follows:
 
Figure 15.jpg
 
Edit Update screen
 
Figure 16.jpg
 

Deleting a record

 
Before Delete
 
I will delete one of the records.
 
Figure 17.jpg
 
Figure 18.jpg
 
Figure 19.jpg
 
Viewing Employees from the Department
 
Figure 20.jpg
 
Details of selected Employee
 
Figure 21.jpg

Up Next
    Ebook Download
    View all
    Learn
    View all