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

Using Fetch Strategy to filter results of child collection

5 Answers 147 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.
Kevin Treweek
Top achievements
Rank 1
Kevin Treweek asked on 30 Nov 2011, 03:25 PM
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

5 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 05 Dec 2011, 11:58 AM
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!

0
Boris Rogge
Top achievements
Rank 1
answered on 19 Mar 2013, 01:12 PM
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
0
Alexander
Telerik team
answered on 22 Mar 2013, 12:13 PM
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.
0
Bob
Top achievements
Rank 1
answered on 10 Sep 2013, 07:32 PM
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
0
Ivailo
Telerik team
answered on 16 Sep 2013, 02:47 PM
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.
Tags
Development (API, general questions)
Asked by
Kevin Treweek
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Boris Rogge
Top achievements
Rank 1
Bob
Top achievements
Rank 1
Ivailo
Telerik team
Share this question
or