none
Unable to fetch child rows when using "ctxt.ObjectTrackingEnabled = False" RRS feed

  • Question

  • I am writing in the following manner:

     

     Using ctxt As New DemoEmpDataContext
                ctxt.ObjectTrackingEnabled = False
                Dim oDept As Dept = ctxt.Depts.Where(Function(d) d.Deptno = 10).FirstOrDefault
                Return If(oDept Is Nothing, Nothing, oDept.Emps.ToList)
            End Using

     

    The above does not return any child rows.  But if I remove the statement "ctxt.ObjectTrackingEnabled=False", it works.  However, I don't want any of the objects to be tracked (and I am using above code in WCF service).  How can I achieve that (or am I thinking wrong?).

     

    I also tried adding and examining with the following stuff:

     

                ctxt.DeferredLoadingEnabled = False
                Dim opt As New DataLoadOptions
                opt.LoadWith(Of Dept)(Function(d) d.Emps)

     

    But, no use.

     

    thanks in advance.

    Sunday, October 26, 2008 11:42 PM

Answers

  • When you set ObjectTrackingEnabled to FALSE you also disabled deferred loading. The code you have posted is using the deferred loading support to load the 'Emps' collection of your 'Dept' entity. If you really do not want to track these objects then you could probably get this working with DataLoadOptions. Rough code below (C#):

     

    // using

    DataLoadOptions opt = new DataLoadOptions();

    opt.LoadWith<Dept>(o => o.Emps);

    ctxt.LoadOptions = opt;

    ctxt.ObjectTrackingEnabled = false;

    // original code here

    // end using

    Monday, October 27, 2008 8:55 AM
    Answerer