.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Articles >> Silverlight >> Post New Resource Bookmark and Share   

 Subscribe to Articles

ADO.NET Data Model and ADO.NET Data Service In Silverlight

Posted By:Diptimaya Patra       Posted Date: April 15, 2010    Points: 25    Category: Silverlight    URL: http://www.dotnetspark.com  

In this article we would see how we can use ADO.NET Entity Data Model as the ORM in Silverlight 3 Application, and ADO.NET Data Service to fetch the data.


In this article we would see how we can use ADO.NET Entity Data Model as the ORM in Silverlight 3 Application, and ADO.NET Data Service to fetch the data.

Creating Silverlight Project

Fire up Visual Studio 2008 and create a new Silverlight 3 Project. Name it as ADONET_Service_SL3_Sample.


Here is the assumption that you must understand is that I have a DataBase "EmployeeDB" which has a table "Employee_Basic_Info".

Now add a ADO.NET Entity Data Model (EmployeeModel.edmx) to the web project as displayed in below figure.


The following screens are for the reference of connecting to the SQL Server, and selecting table from the Database.




After you are done with the connection and selecting tables from the Database you would have the Entity Design as displyed in below figure. I have changed the original names to a good readable name set.


You can find the Mapping details in the below figure.


The following figure displays the heirarchical structure of the Model.


Now we will add a ADO.NET Data Service to the web project, name it as EmployeeWebDataService.svc


After adding the service the VS explorer will open up the cs file for you. There you need to add the EmployeeDBEntities for DataService and uncomment the line(s) for config settings.

The following setting are for Read and Write.


After you are done with the above settings in the svc.cs file. You can see the service in browser as below figure.


Now we need to add the reference to the Silverlight Project, as follows:


Now we would make a simple UI which will hold a DataGrid and few Buttons and TextBoxes for the related queries.


Now for ShowAll Button Click add the following code, before that we need to have a context of the Entity.


Add the following code for Show All Button Click event.


Now add the following code for Search Button Click.


That's it we are done. Now run the application.


Hope this article helps.

 Subscribe to Articles


Further Readings:

Author: krisamigo         Company URL: http://www.dotnetspark.com
Posted Date: May 01, 2010

Hi Patra,

Your article is fantastic. Can you please tell how to use stored procedures instead of simple tables in ado.net entity model.
Appreciate for the quick response as i am breaking my head googling on same.

Thanks in advance

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend