Using Fetch Strategy to filter results of child collection

6 posts, 0 answers
  1. Kevin Treweek
    Kevin Treweek avatar
    1 posts
    Member since:
    Mar 2010

    Posted 30 Nov 2011 Link to this post

    I have an Domain Model which has a one to many relationship between two objects, in this case a Header and Details record.
    I would like to query the header records and also return its associated details records at the same time and so far I have used the following fetch strategy which works fine.

                Dim fetchStrategy As New Telerik.OpenAccess.FetchOptimization.FetchStrategy()
                fetchStrategy.LoadWith(Of Fabs.OA.AccountHeader)(Function(h) h.AccountDetails)
                Me.Context.FetchStrategy = fetchStrategy
                Dim results4 = (From h In Me.Context.AccountHeaders).ToList

    What I would like to do is filter the detail records that are returned at part of the fetch strategy, however this is were things start to fall apart.

    According to this article http://blogs.telerik.com/blogs/posts/10-07-21/new-fetch-optimization-api.aspx, and I quote 

    "Last but not least, we will introduce collection filtering and users will be able to narrow the range of loaded objects to only those that are absolutely necessary. For example, it will be possible to load only shipped orders in the last year by providing the right lambda criteria."

    This is almost exactly what I want to achieve and according to the .LoadWith method in the API documentation (http://www.telerik.com/help/openaccess-orm/topic76.html) I should be able to achieve this with a lambda expression.

    So far I have tried this, however I keep on getting the error "Invalid FetchStrategy definition or FetchMember specification."

    Dim fetchStrategy As New Telerik.OpenAccess.FetchOptimization.FetchStrategy()
    fetchStrategy.LoadWith(Of Fabs.OA.AccountHeader)(Function(h) h.AccountDetails.OrderByDescending(Function(d) d.DateInserted))
    Me.Context.FetchStrategy = fetchStrategy
    Dim results4 = (From h In Me.Context.AccountHeaders).ToList

    Could someone please shed some light on where I am going wrong, or even if this is actually possible?

    Ideally what I would like to achieve is return the header record along with the LATEST detail record determined by the date the details record was inserted.

    Thanks,

    Kevin
  2. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 05 Dec 2011 Link to this post

    Hello Kevin,

    We moved the discussion to a private support channel but I will reply to this thread as well, for others that might want to know the answer.

    Unfortunately this functionality is not part of the product yet, collections with referenced objects cannot be filtered automatically by OpenAccess. The only approach to achieve such functionality is by using a linq query to filter the referenced objects. Here is an example:
    Dim query = From od In context.OrderDetails 
            Where od.OrderID > 10600 
            Group od By od.ProductID Into g = Group 
            Select New With {Key .Key = ProductID, Key .Items = g}

    This way the query result will contain the master object and a collection of filtered detail objects.

    Regards,
    Alexander
    the Telerik team

    Q3’11 of Telerik OpenAccess ORM is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

  3. DevCraft banner
  4. Boris Rogge
    Boris Rogge avatar
    30 posts
    Member since:
    Mar 2006

    Posted 19 Mar 2013 Link to this post

    Hi Telerik,

    Is

    "Last but not least, we will introduce collection filtering and users will be able to narrow the range of loaded objects to only those that are absolutely necessary. For example, it will be possible to load only shipped orders in the last year by providing the right lambda criteria."

    already implemented in the meantime ?

    Thanks
  5. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 22 Mar 2013 Link to this post

    Hello Boris,

    I am afraid this functionality has not been implemented yet. Please feel free to add an entry for it to our Ideas & Feedback portal where other customers can also see it and vote for it. You are encouraged to share as many details as possible about how you see this feature working and perhaps the additional API needed to configure it. All this information will be taken into account when we plan the implementation of the feature.
    Thank you for your feedback.

    Greetings,
    Alexander
    the Telerik team
    Free Webinar: OpenAccess Integration in Sitefinity. SIGN UP NOW.
  6. Bob
    Bob avatar
    46 posts
    Member since:
    Apr 2012

    Posted 10 Sep 2013 Link to this post

    Is the following type of LoadWith syntax being planned?
    quoteFetchStrategy.LoadWith<Quote>(q => q.QuotePages.Where(x => x.QuotePageId == CurrentAppContext.CurrentSession.ActiveQuotePage.QuotePageId));

    It would really help us if this kind of syntax was made available. If it is not yet available, can we formally request this as an enhance within OA?

    Thanks...Bob Baldwin
    Trabon Solutions
  7. Ivailo
    Admin
    Ivailo avatar
    318 posts

    Posted 16 Sep 2013 Link to this post

    Hello Bob,

    Unfortunately, at the moment we cannot guarantee a time-frame for developing such feature, as it is not a part of our plans for 2013.

    Its priority would also be influenced by the number of votes that the Feedback portal brings for this item - if you vote for it there and follow it, you will be notified automatically for any changes in its status. In case you would like to formally request it, you can proceed by contacting us using the support ticketing system.


    Regards,

    Ivailo
    Telerik
    OpenAccess ORM Q2 2013 brings you a more powerful code generation and a unique Bulk Operations support with LINQ syntax. Check out the list of new functionality and improvements shipped with this release.
Back to Top
DevCraft banner