Showing posts with label DynamicDataEntities. Show all posts
Showing posts with label DynamicDataEntities. Show all posts

Thursday, January 3, 2013

Dynamic Data Entities Web Application with Entity Framework


In this article I will explain how we can work with Dynamic Data Entities Web Application which is available at the time of creating a project.
In this article I will show how we can implement CRUD operation without writing a single line of code, and by just un-commenting a line in Global.asax file.
The only thing you have to do is to add a reference in Global.asax file with your project name you created. As my project name dynamicdataentities I will add this as a reference as follows
using dynamicdataentities;


The only thing you have to do after this is to un-comment this line of code from Global.asax file
DefaultModel.RegisterContext(typeof(YourDataContextType), new ContextConfiguration() { ScaffoldAllTables = false });

You have to replace this with the following
DefaultModel.RegisterContext(typeof(codeDBEntities), new ContextConfiguration() { ScaffoldAllTables = true });

Here codeDBEntities is nothing but the connection string which is available in 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



This will create a project with a Master page, a Default page, a Global.asax file along with script and css.
Now let us add Ado.NET Entity Data Model as we did in our last article



As I am already having an connection I am not showing how to add connection, I will proceed with what I have







Open Global.asax file from the solution explorer



You can find some code with comments, we will un-comment the one we needed as follows



Here in place of YourDataContextType you have to replace your context type which will be available in web.config or in Model.edmx





Now run your application



As I integrated 2 tables it is showing those tables, select the required to perform CRUD operations.
I selected Employee and the details are as follows


In the department dropdown you can find out the entire department listed as follows



If I select any that corresponding details were shown as follows



Inserting details to Employee table, if you select Insert New Item it will display as follows



Edit Update screen



Deleting a record:

Before delete: I will delete one of the record


Delete:


After delete:


 Viewing Employees from Department



Details of selected Employee


Any comments welcome..

Please do feel free to ask for any queries...

Popular Posts