LINQ To SQL In Silverlight 3

No.of Views1682
Bookmarked0 times
Downloads 
Votes0
By  dpatra   On  08 May 2010 22:05:45
Tag : LINQ , T-SQL
In this article we would see how can we use LINQ to Sql ORM in Silverlight 3 Application for interacting with SQL Server Database.
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 can we use Linq to Sql ORM in Silverlight 3 Application for interactinig with SQL Server Database.

Creating Silverlight Project

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

 

Image Loading

Now that you have created the Silverlight 3 Application, we would add a LINQ to SQL file that is *.dbml .

 

Image Loading

For your information, I have created a Database named “EmployeeDB” with a table “EMP_BASIC_INFO” with the following details.

 

Image Loading

Now, connect to the SQL Server from Server Explorer as shown in below figure.

 

Image Loading

Drag and Drop the above above displayed table to the Object Relational Designer for Linq to SQL.

Image Loading

Now we would change the above names to be user friendly.

 

Image Loading

To interact with LINQ to SQL we need to have a service that client can call at any time.Add Silverlight enabled WCF Service to the Web Project.
 

Image Loading

In the Service.svc.cs add methods as per your requirement.
I have written two methods such as
 

Image Loading

And

 

Image Loading

After writing the service build the project and get this service’s reference in Silverlight 3 Project as shown in below figure.

Image Loading

After you add the service it would create the ServiceReferences.ClientConfig file.
Now it’s time to design our Silverlight UI in Blend, I have gone for a simple approach, where simple buttons and textbox would help us getting the result which would be displayed in DataGrid.
 

Image Loading

The following XAML is for your reference:

Image Loading

Now we would write client side code to call the service and display the result.
Following code is for Show All Button Click and displaying the result.
 

Image Loading

Following code is for Show the text typed in txtSearch and based on that the result would be displayed.

 

Image Loading

I guess that’s it. Now we can test our application.

 

Image Loading

When some text is typed and Search Button is clicked all the Employee whose name starts with the given text would be displayed.

Image Loading

Hope this article helps.

Sample Project Source

Download source files -1067 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, I am going to show how you can filter your data by RowNumbers that you assigned to your records.
    Published Date : 03/Feb/2011
    SelectMany is Projects each element of a sequence to an IEnumerable and flattens the resulting sequences into one sequence.In this post I am going to show how you can use SelectMany Extension method to achieve the join between related tables easily without writing long queries.
    Published Date : 18/Jan/2011
    Now a days most of the developers are moving towards new LINQ to SQL they find difficult to write down SQL query in C# to query data using LINQ. LINQ is a query language which get integrated in C# to query data form ObjectCollects, SQL, XML etc.
    Published Date : 08/Jan/2011
    I have already written several article about Linq its a great ORM that we can use in various way. The purpose of this post to demonstrate How we can bind custom entity to stored procedure result with use of Linq-To-SQL.
    Published Date : 05/Aug/2010
    Today one of my friend asked me about simple insert,update and delete example with LINQ-To-SQL but at that time i was not having any simple example which will show the power of LINQ-To-SQL Example
    Published Date : 17/May/2010
Comments
By:meenuDate Of Posted:4/27/2012 2:37:10 AM
vb.net code needed
Can u pls provide this same project in vb.net , VS2010 and silver light 4?
By:RRaveenDate Of Posted:9/10/2010 7:16:22 PM
Help
Hi Lakshmi , My author will answer to soon. thank you
By:LakshmiDate Of Posted:9/10/2010 1:28:49 PM
Need with image data
Hai In the above example, i need one more option i.e., how to display the details with image. I mean when we click show all button it displays all the details know, in addition i need image in above case only. I need it urgently plz help me out..... plz Thanks in advance....
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