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

No.of Views938
Bookmarked0 times
Downloads 
Votes0
By  dpatra   On  20 Apr 2010 09:04:33
Tag : Silver Light and XAML , General
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.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

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.
 

Image Loading

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.
 

Image Loading

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

 

Image Loading

 

Image Loading

 

Image Loading

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.

 

Image Loading

You can find the Mapping details in the below figure.

 

Image Loading

The following figure displays the heirarchical structure of the Model.

 

Image Loading

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

 

Image Loading

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.
 

 

Image Loading

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

 

Image Loading

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

 

Image Loading

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

 

Image Loading

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

 

Image Loading

Add the following code for Show All Button Click event.

 

Image Loading

Now add the following code for Search Button Click.

 

Image Loading

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

 

Image Loading

 

Image Loading

Hope this article helps.

Sample Source Code

Download source files -1685 kb

 
Sign Up to vote for this article
 
About Author
 
dpatra
Occupation-Not Provided
Company-Not Provided
Member Type-Expert
Location-Not Provided
Joined date-13 Jul 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
    In this article we’ll have a brief introduction to Microsoft Silverlight, see how it fits with other technologies today, and watch it in action. Get ready!
    Published Date : 05/May/2011
    When you start learning Silverlight and create your first Silverlight application, one thing you will notice XAP file along with HTML and ASPX files. First time after running your Silverlight application you can see XAP file in client bin folder. Before running of Silverlight application, you will not find XAP file in client bin folder.
    Published Date : 19/Apr/2011
    In this article, i will explain how to download or read file asynchronously using WebClient class in Silverlight.The WebClient class is a has many methods,events and properties to support download files in different ways.
    Published Date : 16/Apr/2011
    This article will give a basic introduction of behavior feature in SILVERLIGHT3.0. I will also walkthrough to create a custom behavior.
    Published Date : 05/Apr/2010
    we will see how we can filter a Textbox on Keyboard inputs. We will see how we can block Numeric input from Keyboard.
    Published Date : 16/May/2010
Comments
By:Chinna SrihariDate Of Posted:7/5/2010 8:57:49 PM
ADO.NET Data Model and ADO.NET Data Service In Silverlight 3
What is differance between the bellow articals "RIA Services in Silverlight 4 Using VS 2010" and "ADO.NET Data Model and ADO.NET Data Service In Silverlight 3" abd also where is the details about ADO.NET Data Model and ADO.NET Data Service, what exactly they do here. What are the base classes and what they do? Chinna
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top