DeepFetchGroup takes too much

2 posts, 0 answers
  1. Sebastian
    Sebastian avatar
    1 posts
    Member since:
    Jul 2011

    Posted 05 Mar 2012 Link to this post

    Hello,
    I have an issue when I retrieve a Changset of objects with the deep fetch group.
    Due to my object structure, the function loads too much objects than needed.


    There is a sample of this structure, as you can see, if I attempt to retrieve a ApplicationDocument deeply, all the ApplicationDocuments contained in Application will be loaded too.

    To get my objects, I use this sequence:
    using (IObjectScope scope = ObjectScopeProvider.GetNewObjectScope())
    {
        IQuery query = scope.GetOqlQuery(oqlQuery);
        IQueryResult result = query.Execute();
         
        var container = new ObjectContainer();
        for (int i = 0; i < result.Count; i++)
        {
            container.CopyFrom(scope, i.ToString(), result[i], new FetchGroupCollector(FetchGroupCollector.DeepFetchGroup));
        }
        return container.GetContent();
    }

    So my question is: How is it possible to keep the DeepFetchGroup behavior and to prevent the loading of all the other references?
    By my own investigation, the FetchField attributes are ignored and I can't implement an IObjectCollector because I don't the types by advance.

    Thank you for your future answer.
  2. Ralph Waldenmaier
    Admin
    Ralph Waldenmaier avatar
    202 posts

    Posted 07 Mar 2012 Link to this post

    Hi Sebastian,

    In the scenario you described I'd suggest to specify a fetch plan on the scope just for this query. You can do this by clearing the FetchPlan and setting the MaxDepth property to 1. In this case, the collection of ApplicationDocument's in the Application object is loaded, but the further references are not loaded.
    See the following example:

    using (IObjectScope scope = ObjectScopeProvider.GetNewObjectScope())
    {
        IQuery query = scope.GetOqlQuery(oqlQuery);
        scope.FetchPlan
            .Clear()
            .MaxDepth = 1;
        IQueryResult result = query.Execute();
          
        var container = new ObjectContainer();
        for (int i = 0; i < result.Count; i++)
        {
            container.CopyFrom(scope, i.ToString(), result[i], null);
        }
        return container.GetContent();
    }
     
    I hope this information is useful for you. 
    Do come back if you have any other question.Regards,
    Ralph
    the Telerik team
    Telerik OpenAccess ORM Q1 2012 release is here! Check out what's new or download a free trial >>
  3. DevCraft banner
Back to Top