Introduction to Binding ComboBox and DataGrid Controls in Silverlight 2.0 - Developing WCF Service to serve Business (Entity) Objects collection using LINQ to SQL
(Page 2 of 6 )
Let us start with a new solution:
Create a new Visual Studio 2008 solution.
Add a new WCF Service project named “DemoEmpService.”
Change “Service1” to “EmpService” throughout 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.

<ServiceContract()> _
Public Interface IEmpService
<OperationContract()> _
Function GetEmployee(ByVal empno As Integer) As Emp
<OperationContract()> _
Function GetEmployeeList() As List(Of Emp)
<OperationContract()> _
Function GetDepartmentList() As List(Of Dept)
<OperationContract()> _
Function GetEmployeeListByDept(ByVal deptno As Integer) As List(Of Emp)
End Interface
Imports System.Data.Linq
' NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in Web.config and in the associated .svc file.
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 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 Function GetDepartmentList() As System.Collections.Generic.List(Of Dept) Implements IEmpService.GetDepartmentList
Using ctxt As New DemoEmpDataContext
ctxt.ObjectTrackingEnabled = False
Return ctxt.Depts.ToList
End Using
End Function
Public Function GetEmployeeListByDept(ByVal deptno As Integer) As System.Collections.Generic.List(Of Emp) Implements IEmpService.GetEmployeeListByDept
Using ctxt As New DemoEmpDataContext
Dim opt As New DataLoadOptions
opt.LoadWith(Of Dept)(Function(d) d.Emps)
ctxt.LoadOptions = opt
ctxt.ObjectTrackingEnabled = False
Dim oDept As Dept = ctxt.Depts.Where(Function(d) d.Deptno = deptno).FirstOrDefault
Return If(oDept Is Nothing, Nothing, oDept.Emps.ToList)
End Using
End Function
End Class
Next: Binding Object Collections Silverlight 2.0 ComboBox control dynamically >>
More BrainDump Articles
More By Jagadish Chaterjee