Wednesday, June 3, 2009

EntityDataSource Control ASP.NET

ASP.NET 3.5 sp1 introduces a data source control called EntityDataSource using this control we can bind data to different Data Binding controls.

Now lets start building an example application which gets the data from Northwind database employee table.

Open Visual Studio 2008/2010 and create a Web Application.

Now right click on Solution explorer and add new item and select ADO.NET Entity Data Model and name it as Employees, we will fill EntityDataSource object using this model only.

image

Select the option generate from database and click next

image

Now click on the New Connection button and give required details and create a connection to Northwind Database and click next

image

Once you have connected to database it list all the table procedures etc, here I would like to display data of Employee Table so I selected Employee table and click on finish.

image

Now we are ready with our model once you have done this, in you project you will Employees.edmx file

image

to use our model we need to build our project and check whether there are any error or not, just build the project once.

Our model is ready now, so lets bind the data to a EntityDataSource control for that we need to select a EntityDataSource control from ToolBox and add to Default.aspx, and also add one GridView control to Default.aspx

To bind the model to our EntityDatasource control just select the control and click on > symbol and select configure.

Select Named Connection combo box and select our EntityModel, click on next

image

Select EntitySet name as employees, you will see only one employee table because while creating model we have selected only one table if select more those tables also will be listed, one you select employees all the columns of that table will be listed below select which are appropriate to you here I am selected EmpId, first name and last name and finsh

image

Now we are created EntityDataSource lets bind the data to grid view for that select the grid view and click on ‘>’ symbol and select EntityDataSource1 as data source.

image

Now we are ready with our code just build, run and test.

image

tags: Using EntityDataSource Control, EntityDataModel, ASP.NET 3.5, ADO.NET

2 comments:

  1. Thanks for posting. I guess I was under the impression the Entity Framework data source required you to write the actual queries (kind of like the object data source). I guess I should be experimenting more!

    ReplyDelete
  2. ASP.NET 3.5 sp1 introduces a data source control called EntityDataSource.Thanks for sharing it.

    .net Programmer

    ReplyDelete