Filtering related entities based on another entity

Posts   
 
    
digizen
User
Posts: 8
Joined: 10-Nov-2004
# Posted on: 10-Nov-2007 02:32:24   

Hi,

I am kind of lost, and was wondering if someone could help me with my problem.

I have an entity that contains items, I'll call it "ItemEntity", which is related to itself via another table, "ItemRelationEntity". Items is also related to a third table, ItemNoteEntity.

What I am trying to do is get a list of items, ItemCollection, and its related ItemRelatonCollection, for all ItemEntity entities where ItemNoteEntity exists for the ItemEntity entities.

I was able to get ItemEntity objects filtering correctly (only getting the items that have notes), but when I try to traverse the tree that was pre-fetched, all the Item entities show up, regardless of whether there were notes or not.

Here's the code:

IPredicateExpression FilterRel = (ItemNoteFields.F_Guid != System.DBNull.Value);

IPredicateExpression FilterItem = (ItemNoteFields.F_Guid != System.DBNull.Value);

RelationCollection relations = new RelationCollection();

relations.Add( ItemNoteEntity.Relations.ItemEntityUsingF_ItemGuid, JoinHint.Right); relations.Add( ItemEntity.Relations.ItemRelationEntityUsingF_ItemGuid, JoinHint.Left);

IPrefetchPath path = new PrefetchPath((int)EntityType.ItemEntity);

path.Add( ItemEntity.PrefetchPathItemRelationLineage, 0, FilterRel, relations);

Items.GetMulti(FilterItem, 0, null, relations, path);

Can anyone assist? I am using LLBLGen 2.5.

Thanks, Greg

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 11-Nov-2007 22:55:36   

relations.Add(
        ItemEntity.Relations.ItemRelationEntityUsingF_ItemGuid,
        JoinHint.Left);

I think this relation doesn't make any difference as you aren't filtering on that fields at FilterRel. I think isn't needed.


IPredicateExpression FilterItem = 
       (ItemNoteFields.F_Guid != System.DBNull.Value);
...
Items.GetMulti(FilterItem, 0, null, relations, path);

Are you missing to include FilterItem at you GetMulti call?

David Elizondo | LLBLGen Support Team
digizen
User
Posts: 8
Joined: 10-Nov-2004
# Posted on: 13-Nov-2007 04:46:13   

daelmo wrote:


relations.Add(
        ItemEntity.Relations.ItemRelationEntityUsingF_ItemGuid,
        JoinHint.Left);

I think this relation doesn't make any difference as you aren't filtering on that fields at FilterRel. I think isn't needed.


IPredicateExpression FilterItem = 
       (ItemNoteFields.F_Guid != System.DBNull.Value);
...
Items.GetMulti(FilterItem, 0, null, relations, path);

Are you missing to include FilterItem at you GetMulti call?

Thanks for your help. I removed the unnecessary filters. I figured out the answer to my problem - I needed to insert a CustomFilter for the relations got the desired output.

Thanks again, Greg