Windows Scripting
  Home arrow Windows Scripting arrow Page 2 - Designing WCF DataContract Classes Using t...
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

Designing WCF DataContract Classes Using the LINQ to SQL Designer
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2009-01-14

    Table of Contents:
  • Designing WCF DataContract Classes Using the LINQ to SQL Designer
  • Creating WCF DataContract classes visually using LINQ to SQL Designer
  • Creating WCF DataContract classes visually using LINQ to SQL Designer: Accessing in Silverlight
  • Inheriting WCF DataContract classes visually using LINQ to SQL Designer
  • Inheriting WCF DataContract classes visually using the LINQ to SQL Designer: accessing

  • 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


    Designing WCF DataContract Classes Using the LINQ to SQL Designer - Creating WCF DataContract classes visually using LINQ to SQL Designer


    (Page 2 of 5 )

    If you are new to WCF, please refer my article available at http://www.aspfree.com/c/a/BrainDump/Developing-an-Object-Oriented-Business-Component-Using-WCF-and-Visual-Studio-2008/

    The entity classes (which hold information) are called DataContract classes in WCF. If the WCF Service has many DataContract classes, we will generally code them manually. The class designer can help us to a certain extent, but not a lot.

    I have authored quite a few articles on "LINQ to SQL" on this web site. It is another great technology from Microsoft which enables us to create a DAL (Data Access Layer) in a RAD manner. Now we have the LINQ to SQL Designer. It is very similar to a class designer. However, it is tightly integrated with database objects.

    In all of my previous articles, I used "LINQ to SQL" or "LINQ to SQL Designer" to simply leverage the capabilities of a DAL. However, we can also use the designer to quickly create WCF-supported "DataContract" classes visually and much more efficiently than a class designer.

    Let us start creating a new solution to demonstrate this:

    • 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 figure.


    The above automatically creates the respective database context, along with "DataContract" classes with respect to "Emp" and "Dept." Make sure that you don't forget to set "SerializationMode" to "UniDirectional" (otherwise it won't create "DataContract" classes).

    Okay. Sometimes, we may need to create some custom strongly-typed DataContract classes. These DataContract classes may not have any object directly related to the database (they may be part of a business information exchange). Even in these scenarios, we can make use of the LINQ to SQL designer.


    • Add one more "LINQ to SQL Classes" item to the project ("EmpViews").

    • Drag and drop a "Class" item from the toolbox on to the "LINQ to SQL Designer" surface.

    • Rename the class to "EnameDname" and add two properties (by right clicking on the class in the designer), "Ename" and "Dname."

    • Set the "SerializationMode" to "UniDirectional" for the context.

    • Save the DBML.


    At this point, if you open the "EmpViews.designer.vb," you should see the "EnameDname" class defined as the "DataContract" class as follows:


    <Table(Name:=""), _

    DataContract()> _

    Partial Public Class EnameDname

     

    Private _Ename As String

     

    Private _Dname As String

     

    Public Sub New()

    MyBase.New

    End Sub

     

    <Column(Storage:="_Ename", CanBeNull:=false), _

    DataMember(Order:=1)> _

    Public Property Ename() As String

    Get

    Return Me._Ename

    End Get

    Set

    If (String.Equals(Me._Ename, value) = false) Then

    Me._Ename = value

    End If

    End Set

    End Property

     

    <Column(Storage:="_Dname", CanBeNull:=false), _

    DataMember(Order:=2)> _

    Public Property Dname() As String

    Get

    Return Me._Dname

    End Get

    Set

    If (String.Equals(Me._Dname, value) = false) Then

    Me._Dname = value

    End If

    End Set

    End Property

    End Class


    The above class can be directly used as a "WCF data contract object exchange" without any modification.

    More Windows Scripting Articles
    More By Jagadish Chaterjee


       · Hai,This is my next article in the series of WCF tutorials. Enjoy and let me...
     

    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 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek