none
ORM with WCF RRS feed

  • Question

  • I have an ORM designed db set up. I have turned the Serialization Mode to Unidirectional on the datacontext class (via the design time properties). I also need to turn off deferred loading as is outlined in the following: http://msdn.microsoft.com/en-us/library/bb546184.aspx

    However, I can't find out how to do this. I need to set this up via the properties at design time because my ORM model will be on a middle tier using WCF.

    How can I turn off deferred loading?
    0I also want to use a middle-tier WCF application (in conjunction with the LINQ TO SQL classes I have already set up via the ORM). This will pass data back & forth between the presentation & database tiers.

    I'm just confused as to how to set this up :(

    I've tried looking at articles specifically about this, but no article I've found actually does this. This is such a basic scenario, that I'm surprised I can't find it anywhere.

    I've got the ORM set up (except for the deferred loading being turned off). I need to create the WCF service and integrate it with the ORM project. I need to set up methods in the WCF service for updating data in the database, but am unsure as to how to accomplish this with the ORM LINQ TO SQL classes. I know how to do it using it without the ORM and access the db directly via ado.net, but I want to try and use the ORM LINQ TO SQL classes with the WCF service.

    How can I accomplish this. Even some high level bullet points would be appreciated.

    Thanks.
    --------------------------------------------------------------------------------
    Bill Yeager


    Bill Yeager
    Thursday, July 9, 2009 6:00 PM

All replies

  • There's a property on the datacontext where you can set that: dc.DeferredLoading=false;

    I usually override the datacontext constructor in a partial class and set up stuff like deferred loading but also auditing, logging etc in there - that way I can control from code whether I want it or not. (Sometimes I do want deferred loading for stuff that is internal to a WCF service, i.e. the objects will not travel over the wire...)

    E.g.:

    public SomeDataContext(string connectString, bool enableProfiling, bool disconnect, Guid userID)
        : this(connectString)
    {
        _currentUserID = userID;
    
        if (disconnect == true)
        {
            this.DeferredLoadingEnabled = false;
        }
    
        if (enableProfiling == true)
        {
            string profilerOutput = Settings.ProfilerOutput;
            _profiler = this.BeginProfiling(profilerOutput, new PageReadFilter(10000), ExecutionPlanMode.Estimated, true);
            _profiler.LogError += new EventHandler(L2SProfiler_LogError);
        }
    }

    Kristofer - Huagati Systems Co., Ltd. - Cool tools for Linq-to-SQL and Entity Framework: www.huagati.com/dbmltools (VS designer add-in), www.huagati.com/L2SProfiler (query profiler for L2S)
    Friday, July 10, 2009 3:30 AM
    Answerer
  • being turned off). I need to create the WCF service and integrate it with the ORM project. I need to set up methods in the WCF service for updating data in the database, but am unsure as to how to accomplish this with the ORM LINQ TO SQL classes. I know how to do it using it without the ORM and access the db directly via ado.net, but I want to try and use the ORM LINQ TO SQL classes with the WCF service.

    Oh, and as for the updating - simply re-attach the objects to the datacontext when you get them back from the client, e.g.:

    Attach for updates:
    dc.FlightSchedules.Attach(fs, true);

    ..and the usual insertonsubmit/deleteonsubmit for inserts/deletes:

    dc.FlightCodeShares.InsertAllOnSubmit(flightCodeShare);
    ...
    dc.ClassHierarchyClasses.DeleteAllOnSubmit(deletedMappings);

    One thing that really helps for working with L2S and WCF is to have timestamps everywhere. One timestamp column in every table and the re-attach scenarios are a lot easier to deal with.
    Kristofer - Huagati Systems Co., Ltd. - Cool tools for Linq-to-SQL and Entity Framework: www.huagati.com/dbmltools (VS designer add-in), www.huagati.com/L2SProfiler (query profiler for L2S)
    Friday, July 10, 2009 3:40 AM
    Answerer
  • Kristofer, thanks for the input...

    From what I've read, L2S at this point really doesn't do n-tier apps. It's more geared form asp.net web pages --> L2S with the LinqDataSource control.

    I think I'll wait for the ado.net entity framework to become more mature in VS 2010 before I start using it in an n-tier fashion.
    Bill Yeager
    Friday, July 10, 2009 4:37 PM
  • Kristofer, thanks for the input...

    From what I've read, L2S at this point really doesn't do n-tier apps. It's more geared form asp.net web pages --> L2S with the LinqDataSource control.

    I think I'll wait for the ado.net entity framework to become more mature in VS 2010 before I start using it in an n-tier fashion.
    Bill Yeager

    L2S works fine in n-tier apps, with a few minor quirks that can be worked around with extension methods. I'm currently working on a 350+ table distributed app using L2S+WCF. Besides a few additional one-liners for resyncing changes here and there and a handful of extension methods to support the same, it works beautifully...

    If you run into any L2S n-tier showstoppers, please post here and I'm sure that I or others can provide workarounds.
    Kristofer - Huagati Systems Co., Ltd. - Cool tools for Linq-to-SQL and Entity Framework: www.huagati.com/dbmltools (VS designer add-in), www.huagati.com/L2SProfiler (query profiler for L2S)
    Sunday, July 12, 2009 5:13 PM
    Answerer