This is a migrated thread and some comments may be shown as answers.

DeepFetchGroup takes too much

1 Answer 51 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sebastian
Top achievements
Rank 1
Sebastian asked on 05 Mar 2012, 05:27 PM
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.

1 Answer, 1 is accepted

Sort by
0
Ralph Waldenmaier
Telerik team
answered on 07 Mar 2012, 01:31 PM
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 >>
Tags
Development (API, general questions)
Asked by
Sebastian
Top achievements
Rank 1
Answers by
Ralph Waldenmaier
Telerik team
Share this question
or