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.
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.Step-3:
Select the Generate from Database option in the wizard and then click the next button.Step-4:
After clicking the Next button a new window will appear for connecting the Data Connection purpose, see the below screen shot.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".Step-6:
After finish that configuration a new model has been created under App_Code folder. Refer below screen shot.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.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.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.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.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.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.