Using EntityDataSource control in ASP.net


In this article I'm trying to explain how to work with EntityDataSource control for displaying database data to our DataControls. During this process we can able to learn how to configure EntityDataSource control and how to connect with DataControl. This is very simple to communicate with our Database.

Using EntityDataSource control in ASP.net:



In this article I'm trying to explain how to work with EntityDataSource control for displaying database data to our DataControls. During this process we can able to learn how to configure EntityDataSource control and how to connect with DataControl. This is very simple to communicate with our Database.

Follow below steps to configure EntityDataSource control in our Application.

Step-1:



Right click on Project folder and then add new item option then choose ADO.NET Entity Data Model and then give a name for that.

1

Then click on Add button for adding .edmx file into our project.

Step-2:



While adding EDM a new window will appear like a confirmation message with “yes/ No/ Cancel" options when you click “yes" a new window will appear for configuring EDM Object.

2

Step-3:



Select the Generate from Database option in the wizard and then click the next button.

3

Step-4:



After clicking the Next button a new window will appear for connecting the Data Connection purpose, see the below screen shot.

4

Step-5:



Provide Entity name for that and then click on Next button then it's fetch database objects information like tables, views, stored procedures. Then choose your object and then click on Finish button. In the below example I just choose Table name as “tblEmployee".

5

Step-6:



After finish that configuration a new model has been created under App_Code folder. Refer below screen shot.

6

Step-7:



Now the time to implement the application using Entity Data Model control. Just create a page with the name EntityDataSource.aspx. and drag & drop EntityDataSource object available under DataControls tab.

7

Step-8:



Now the time to configure with Entity Data Source, just click on the smart tag and then choose Data Source option then choose Entity Data Source object. Then a new window will appear for configure the Entity Data Source object. Choose the Entity object name available under Named Connection dropdown then click on Next button.

8

Step-9:



Its redirect to new window there you can choose Entity table name and choose columns to include in that result display time and then click on Finish button.

9

Step-10:



Now, configuration Entity Data Model has been completed now the time to display the result into DataControls. Simply drag&drop gridview control to the design page and then click on smart tag then choose Data Source object as Entity Data Model then see the gridview control design.

10

Step-11:



Just see the source code of gridview after configure with Entity Data Model.


<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=EngsoftEntities" DefaultContainerName="EngsoftEntities"
EnableFlattening="False" EntitySetName="tblEmployees"
Select="it.[Emp_Name], it.[Emp_job], it.[Emp_Dep]">
</asp:EntityDataSource>


<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

DataSourceID="EntityDataSource1"

>
<Columns>
<asp:BoundField DataField="Emp_Name" HeaderText="Emp_Name" ReadOnly="True"
SortExpression="Emp_Name" />
<asp:BoundField DataField="Emp_job" HeaderText="Emp_job" ReadOnly="True"
SortExpression="Emp_job" />
<asp:BoundField DataField="Emp_Dep" HeaderText="Emp_Dep" ReadOnly="True"
SortExpression="Emp_Dep" />
</Columns>
</asp:GridView>


Step-12:



Now, it's a time to check the output just Press F5 on the key board and then see the output.

11

Conclusion:



I hope this article will help you those who are looking for the same and those who are new to implement EntityDataSource control in your applications.

About Author:



This is Naveen, I completed my MCA and I have around 3 years of experience in ASP.net while implement Web Applications. For past 3 years I learn no.of Technologies while implement my applications apart from that I try to learn new technologies and I try to implement that while implement my project.


Article by naveensanagasetti
I hope you enjoyed to read my article, If you have any queries out of this then please post your comments.

Follow naveensanagasetti or read 139 articles authored by naveensanagasetti

Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: