i

ASP.Net A Complete Guide

EntityDataSource

The EF can used to create websites using the ASP.NET framework. The EntityDataSource control is a set of Web Server Data-source controls. It can used to bind an EDM to data-bound controls on the page. These controls are grids, forms, drop-down list and can used to create, read, update, and delete data.

We will have a look on below example that will guide for using the EntityDataSource

In the below image you can see the “EntityDataSource” control is available in toolbox. We can use that just by doing the drag and drop on web form.

 

For using the entity framework, we need to add the Add an ADO.NET Entity Data Model in web application. We can see that in below image. Click on Solution explorer->Add new item-> ADO.NET Entity Data Model. Click on add to continue.

As we have created database already we can use the database first approach here. As shown in the below image select first option & click on continue.

Then you will see window like below from that click on the “New Connection” & click on next button.

 

 

As per shown in below image you can select the server name from the drop down list.

From the connect to database section select your database name:

Click ok to contine.

After this step you will be redirected to the new window where EDM will create connection string and that get displayed in the “ConnectionString” field.

Then go to your web form in design mode. Click on the task option “Choose Data Source” and set the EntityDataSource id that here we see it in drop down we need to select that one that is “EntityDataSource1”. After selecting that the new window will get open and that will redirect on the “Configure ObjectContext” window.

Here from the drop down just select the database name under the “Named Connection”

 

When click on the next button you will be redirecte to the below window from there select the framework window that is most suited with the installed visual studio.

When click on next button to continue below window will get display.

Click on finish button to complete the configuration of EDM.

To bind the data which is in your table select the “GridView” control from the toolbox? Drag and drop it on the design page.

Then bind the “EntityDataSource” like shown above image. As in, my table there were no records present it shows by default the dummy data. You can see in the below image.

Now just build and run the application to see the output.