unable to filter by child entities.

Posts   
 
    
johnd
User
Posts: 6
Joined: 09-Aug-2012
# Posted on: 09-Aug-2012 01:29:02   

Hi,

Lets say I have the following query:

select r.Container, r.[Key], rv.Culture, rv.Value from Framework.StringResource r inner join Framework.StringResourceValue rv on r.ID = rv.StringResourceID where rv.Culture = 'fr' and r.Container = 'AddEditLocations'

How do I construct the PrefetchPath, RelationPredicateBucket and invoke the code such that I am able to filter by StringResource and StringResourceValue column? I have read through the documentation and I am lost.

Here is my code but its not working

var prefetchPath = new PrefetchPath2(EntityType.StringResourceEntity) { StringResourceEntity.PrefetchPathStringResourceValues }; var bucketContainer = new RelationPredicateBucket(); bucketContainer.PredicateExpression.Add(StringResourceFields.Container == container); bucketContainer.PredicateExpression.Add(StringResourceValueFields.Culture == culture);

Please help. Thanks..

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 09-Aug-2012 06:16:13   

Hi John,

You are almost there. You just need to add a relation so the filter on the related entity is recognized:

var prefetchPath = new PrefetchPath2(EntityType.StringResourceEntity); prefetchPath.Add(StringResourceEntity.PrefetchPathStringResourceValues);

var bucketContainer = new RelationPredicateBucket(); bucketContainer.PredicateExpression.Add(StringResourceFields.Container == container); bucketContainer.PredicateExpression.Add(StringResourceValueFields.Culture == culture); bucketContainer.Relations.Add(StringResourceEntity.Relations.StringResourceValueEntityUsingStringResourceID); // ...

The thing is: What do you want of these options?: a. Filter the main collection (StringResource) using the Container field, and for each StringResource, fetch the childs (StringResourceValue) filtered by the Culture field.

b. Filter the main collection (StringResource) using the Container filed and a related field (StringResourceValue.Container). And for each StringResource fetch all its childs (StringResourceValue).

What you are doing right now is option (a). If you want (b) you should move the (StringResourceValueFields.Culture == culture) to the prefetchPath predicate, there is a prefetchPath constructor for that.

So, adding a relation is different that adding a prefetchPath. More about this at http://www.llblgening.com/archive/2009/10/prefetchpaths-in-depth/

David Elizondo | LLBLGen Support Team
johnd
User
Posts: 6
Joined: 09-Aug-2012
# Posted on: 09-Aug-2012 18:14:13   

Thanks.. this is working for now.