How to use FetchStrategy?

2 posts, 0 answers
  1. Zhaoning
    Zhaoning avatar
    7 posts
    Member since:
    Jan 2012

    Posted 05 Jan 2012 Link to this post

    i want to us FetchStrategy class to load of specified related data, and I have read the manual, but there are still some problems.
    example : 
    Package, PackageItem,Sample,TestRequest
    the relation of Package and PackageItem is one to multi;
    the relation of PackageItem and Sample is one to multi;
    the relation of Sample and TestRequest is one to multi;

    1. when i get Package data,it can load PackageItem data and Sample data(The value of the MaxFetchDepth must be greater than 0 and the default one is 3.).  it's normal,I can understand.

    2. when i get PackageItem data,it can load Sample data and TestRequest data.  it's normal,I can understand.

    3.but if i do step 1 after i have done step2,then all of the Package data, PackageItem data ,Sample data and TestRequest data will be loaded.i don't set any FetchStrategy Class to Context,at this time. Why???

    4.whether step 1 or step 2,it's still load three depth data,no matter whether I set MaxFetchDepth = 1.Why???

    my english is very poor,i hope I have expressed it clearly.
  2. Zoran
    Zoran avatar
    534 posts

    Posted 09 Jan 2012 Link to this post

    Hi Zhaoning,

     As for question number 3, can you share with us the code that you use to fetch the PackageItem and after that the Package objects(steps 2 and 1). If the context instance is one and the same and you have already loaded PackageItem and Sample, it is expected behavior that Package, PackageItem and Sample are loaded once again if you are trying to load the Package object. The reason for this is that the FetchStrategy is being applied on the top-most object in the graph and in this case that object is Package. That means that whenever you load the Package object you will get the PackageItem and Sample objects loaded with it even if you have loaded those objects in another way before that.

    Sending us a code-sample will really be helpful for us to give you the answers for questions 3 and 4 as there are a lot of ways the Fetch Strategies can be applied and they should be used carefully so no additional and unexpected queries are produced.

    All the best,
    the Telerik team

    SP1 for Q3’11 of Telerik OpenAccess ORM is available for download

Back to Top