Windows Scripting
  Home arrow Windows Scripting arrow Page 2 - Database operations using Silverlight 2.0 ...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Database operations using Silverlight 2.0 WCF and LINQ to SQL
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2008-12-10

    Table of Contents:
  • Database operations using Silverlight 2.0 WCF and LINQ to SQL
  • Developing a WCF Service to interact with LINQ to SQL for all CRUD operations
  • Developing a Silverlight 2.0 page to demonstrate CRUD functionality
  • Developing a Silverlight 2.0 page to demonstrate CRUD functionality: code behind
  • Developing a Silverlight 2.0 page to demonstrate CRUD functionality: Explanation

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Database operations using Silverlight 2.0 WCF and LINQ to SQL - Developing a WCF Service to interact with LINQ to SQL for all CRUD operations


    (Page 2 of 5 )

    Let us start with a new solution:

    • Create a new Visual Studio 2008 solution.

    • Add a new WCF Service project named “DemoEmpService.”

    • Modify all “Service1” to “EmpService” everywhere in the project (steps are shown in my previous articles).

    • Add a “LINQ to SQL Classes” item to the project (“DemoEmp.dbml”)

    • Using “Server Explorer,” drag and drop “Emp” and “Dept” tables as shown in the following image.

    • Modify “IEmpService.vb” as shown below:


    <ServiceContract()> _

    Public Interface IEmpService


    <OperationContract()> _

    Function GetEmployee(ByVal empno As Integer) As Emp


    <OperationContract()> _

    Function GetEmployeeList() As List(Of Emp)


    <OperationContract()> _

    Sub Add(ByVal objEmp As Emp)


    <OperationContract()> _

    Sub Update(ByVal objEmp As Emp)


    <OperationContract()> _

    Sub Delete(ByVal empno As Integer)


    End Interface



    • Implement the same in “EmpService” (service) class as follows:


    Imports System.Data.Linq


    Public Class EmpService

    Implements IEmpService


    Public Sub New()

    End Sub


    Public Function GetEmployeeList() As System.Collections.Generic.List(Of Emp) Implements IEmpService.GetEmployeeList

    Using ctxt As New DemoEmpDataContext

    ctxt.ObjectTrackingEnabled = False

    Return ctxt.Emps.ToList

    End Using

    End Function


    Public Sub Add(ByVal objEmp As Emp) Implements IEmpService.Add

    Using ctxt As New DemoEmpDataContext

    'adding a new row

    ctxt.GetTable(Of Emp).InsertOnSubmit(objEmp)

    'saving rows added

    ctxt.SubmitChanges()

    End Using


    End Sub


    Public Sub Delete(ByVal empno As Integer) Implements IEmpService.Delete

    Using ctxt As New DemoEmpDataContext

    Dim objEmpOld As Emp = ctxt.GetTable(Of Emp).SingleOrDefault(Function(p) p.Empno = empno)

    If objEmpOld IsNot Nothing Then

    'delete row

    ctxt.GetTable(Of Emp).DeleteOnSubmit(objEmpOld)

    'save changes

    ctxt.SubmitChanges()

    End If

    End Using

    End Sub


    Public Function GetEmployee(ByVal empno As Integer) As Emp Implements IEmpService.GetEmployee

    Dim objEmp As Emp = Nothing


    Using ctxt As New DemoEmpDataContext

    'retrieve emp row

    objEmp = ctxt.GetTable(Of Emp).SingleOrDefault(Function(p) p.Empno = empno)

    End Using


    Return objEmp

    End Function


    Public Sub Update(ByVal objEmp As Emp) Implements IEmpService.Update

    Using ctxt As New DemoEmpDataContext

    Dim objEmpOld As Emp = ctxt.GetTable(Of Emp).SingleOrDefault(Function(p) p.Empno = objEmp.Empno)

    If objEmpOld IsNot Nothing Then

    'modify row

    objEmpOld.Ename = objEmp.Ename

    objEmpOld.Sal = objEmp.Sal

    objEmpOld.Deptno = objEmp.Deptno

    'save changes

    ctxt.SubmitChanges()

    End If

    End Using

    End Sub


    End Class



    More Windows Scripting Articles
    More By Jagadish Chaterjee


       · Hai,This is my next in series focusing on development using Silverlight 2.0, WCF...
       · Excellent Article. But is it the best solution or there are any other solutions as...
     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek