What is the use of entity datasource?

Posted by Prabu_Spark under ASP.NET on 4/18/2013 | Points: 10 | Views : 1606 | Status : [Member] | Replies : 1
Hi sir,
I want to know the use of entity datasource. Kindly give me some examples to understand clearly.

With regards,


Posted by: Kmandapalli on: 4/18/2013 [Member] Silver | Points: 25

Hi Prabhu,

DataSource controls were introduced in ASP 2.0. These are the controls that can be bound to external data sources such as Databases, XML files, and so on. We can find these controls under Data tab in toolbox in ASP.Net (Sql DataSource, Linq DataSource, Object DataSource).

They can be used to connect to and retreive data from various types of data sources without the need to write code to perform such operations.

Entity DataSource is a new DataSource for ASP.NET 3.5 like other controls which makes binding ASP.NET UI controls to Entity Data Models very easy. This can be used in data binding scenario. This helps to create data driven applications quickly and easy and to perform CRUD (Create, Update, Delete) operations on data based in an Entity Data Model.

The code gets minimized and we can easily develop the code for our application.

Note :
While using Entity Data Model, the table we use should definitly contain a primary key constraint otherwise we cannot access the table using Entity Data Model.

Step 1:
Open VisualStudio 2008 or 2010 and add a Web Application and name it.

Step 2:
Open Toolbox, under Data controls tab drag and drop a GridView control and Entity DataSource onto Default.aspx page.

Step 3:
Right click on Solution Explorer, select Add, under that select Add new item.
Then click on Data, and under that select Entity ADO.NET Model.

Step 4:
Now, under Choose Model Contents select Generate from Database and click Next.

Step 5:
Choose your Data Connection and click Next.
By default it saves connection string in configuration file.

Step 6:
Then, under tables, select your table and click next.
Now, your dataobject appears as below.

Step 7:
Now, click on Design, and click on the arrow of the entity datasource to configure the Entity DataSource control.

Step 8:
Build the solution.
Then configure ObjectContext and click next.

Step 9:
Configure DataSelection and click next.

Step 10:
Now, click on the arrow of the GridView to configure.
Choose you data source id for GridView Data Source. You can enable Sorting, Deleting, Selection, Editing, Paging.

Step 11:
Click on Source and you can find the total code.

Step 12:
Now run the solution and grid appears on the web page.


Kavya Shree Mandapalli

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response