locked
3-Tier Application

    Question

  • I currently have a prototype 3-tier app based on the following architecture:

    • WPF for the smart-client app
    • SQL 2005 on the back-end
    • WCF service on the middle tier

    The WCF service currently retrieves SQL data using an OleDbDataAdapter with a SQL string, and fills a DataSet.  This is then mapped into a generic list collection and returned to the WPF client app via WCF.  The WPF app then obtains the generic list collection object via WCF magic (both the client app and the service app share the same assembly that defines the class with the [DataContract]).

    Now that the latest Orcas CTP is out, I am wondering how LINQ to SQL (and possibly LINQ over DataSet) fits in.  I would assume that LINQ to SQL would be used to replace the OleDbDataAdapter / SQL string code on the middle-tier service.  But what about serializing the object using WCF?  Does LINQ (or ADO.NET Entities) help with this, or should I continue using my own [DataContract] class for this?  Should I instead serialize a DataSet?

    On the WPF client side, it would seem that LINQ over DataSet could be used instead of my own class, correct?  Could the code-generated class that LINQ to SQL creates (that models the underlying database table) be used on both the client side tier and middle tier?

    Thanks for any help on this.

    -Larry

     

    Saturday, March 03, 2007 1:33 AM

Answers

  • With a disconnected environment, the challenge is retaining the context (list of changed fields, etc). In a SOA environment, you do not typically pass that information. The same is true with the disconnected nature of ASP. In those cases, you need to leverage the System.Data.Table.Attach<T> method to reconnect an object to an existing data context. The context is not passed as part of a service call. Unfortunately the current "help" file isn't much help for this method. It is documented in the May CTP drop.

    Below is a sample to update a record returned from a service call. I'll let you work out the WCF attributes.

    Public Sub UpdatePost(post as PostItem) 

    Dim dc As New ThinqLinq.BO.LinqBlogDataContext
            If post.ID = 0 Then
                post.PublicationDate = Now()
                dc.PostItems.Add(post)
            Else
                dc.PostItems.Attach(post)
            End If
            dc.SubmitChanges()
    end sub

    Jim Wooley
    http://devauthority.com/blogs/jwooley
    http://ThinqLinq.com (coming soon)
    http://LinqInAction.Net

    Saturday, March 03, 2007 9:45 PM

All replies

  • With a disconnected environment, the challenge is retaining the context (list of changed fields, etc). In a SOA environment, you do not typically pass that information. The same is true with the disconnected nature of ASP. In those cases, you need to leverage the System.Data.Table.Attach<T> method to reconnect an object to an existing data context. The context is not passed as part of a service call. Unfortunately the current "help" file isn't much help for this method. It is documented in the May CTP drop.

    Below is a sample to update a record returned from a service call. I'll let you work out the WCF attributes.

    Public Sub UpdatePost(post as PostItem) 

    Dim dc As New ThinqLinq.BO.LinqBlogDataContext
            If post.ID = 0 Then
                post.PublicationDate = Now()
                dc.PostItems.Add(post)
            Else
                dc.PostItems.Attach(post)
            End If
            dc.SubmitChanges()
    end sub

    Jim Wooley
    http://devauthority.com/blogs/jwooley
    http://ThinqLinq.com (coming soon)
    http://LinqInAction.Net

    Saturday, March 03, 2007 9:45 PM
  • Thanks, the May 2006 CTP does have better docs for this as you mention.

    BTW, I see there's a new Custom Attributes property in the object designer, and when I add DataContract as an attribute for my DataClass object, the attribute gets generated in the designer.cs file.  But when I compile I get an error because the generated file does not have a "using System.Runtime.Serialization;" statement.  Until I figure out how to tell the designer to generate this line, I have to manually add it each time the file changes.  Any way to do this?

    -Larry

     

    Sunday, March 04, 2007 2:21 AM
  • In VB you would be able to add a global reference to the namespace. I don't know a way to do that in C# at this point though. You should be able to use the fully qualified namespace in the custom attributes property. However, it appears that the Custom Attribute is not applied to the generated class, but rather to the XML based .dbml file.

    Jim Wooley
    http://devauthority.com/blogs/jwooley

    Sunday, March 04, 2007 3:35 AM
  •  

    for your information I had to add extra line after  dc.PostItems.Attach(post);

    something like post.UpdateDate = DateTime.Now;  (i.e. statement that was updating attached object)

    to force the data context to start tracking changes so when calling SubmitChanges(), update is executed on the object.

    I also had to change the update command, as by default it was using optimistic concurrency and that is not what I wanted

    regards

    Rafal

    http://www.merlinprj.com

    Sunday, March 04, 2007 3:58 PM
  • Is this still how it works in March CTP?
    Tuesday, March 13, 2007 1:02 PM