Lazy Load Filter for related collection

Posts   
 
    
MPW
User
Posts: 27
Joined: 28-Aug-2007
# Posted on: 04-Jan-2015 23:49:57   

I create a collection of entities (PersonCollection). This has several related entities. If this person collection is presented to the user via UI Data Browser and they select a related entity (Results), the lazy load will fetch a collection of those entities. What if I want that related collection filtered, say by "Result.AcademicYear". I don't want a prefetch path with a filter as I don't want to load all the data for all the entities only the few the user may select.

The Person.GetMultiResult() has a filter option but how do I set it?

Thanks Mark

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-Jan-2015 01:49:03   
Person.GetMultiResult(true, new PredicateExpression(Result.AcademicYear >= 2013));
David Elizondo | LLBLGen Support Team
MPW
User
Posts: 27
Joined: 28-Aug-2007
# Posted on: 05-Jan-2015 23:06:16   

Hi David

That's fine for a solution in code, but in a UI control when the user selects a related entity I have no control over what function is executed and can't force the filter. I need to set the filter on the initial collection so it executes when a related entity is selected. In fact, even more than, that I would like to set different filters for different related entities.

Regards Mark

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 06-Jan-2015 06:58:16   
MPW
User
Posts: 27
Joined: 28-Aug-2007
# Posted on: 01-Feb-2015 19:07:42   

Sorry for the slow response and thanks for the link, but that doesn't seem to solve the issue. This is part of a generic query designer in which the end user can set filters for related entity collections. The reporting entities are all based on a SQL views. A StudentViewEntity has various related 1:n entity collections, such as classes, awards, activities.

It's easy to override/modify the GetMulti() to apply a filter if one is set, but how to set the filter. I could create a static filter dictionary with <entitynames, predicates> and use that in the GetMulti(), but that means there can only be one filter dictionary. Perhaps some DI framework is the way to go so that the filter collection is instance based per report rather than juts one static class.

Ideally the user would set the filtering on the related classes and I would then turn that into prefetch paths and fetch the data in one go. At the moment I'm using dynamic linq to construct the linq query expression.


IDataSource d = meta.GetQueryableForEntity((int)Data.Model.EntityType.StudentViewEntity);
Expression body = System.Linq.Dynamic.DynamicExpression.Parse(null, filterString, null);
var query = d.Provider.CreateQuery(body);
f = ((ILLBLGenProQuery)query).Execute<StudentViewCollection>();

I'll perhaps have to go back and look at creating prefetch paths in Linq or even go back to LLBLGEN Predicates.

Mark

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 02-Feb-2015 05:43:33   

Hi Mark,

Yes, your workarounds and possible solutions are totally possible. A Dictionary or a DI Framework could help you as you mentioned.

David Elizondo | LLBLGen Support Team