Merging IRelationPredicateBucket

Posts   
 
    
stefcl
User
Posts: 210
Joined: 23-Jun-2007
# Posted on: 26-Oct-2007 18:16:16   

Hello,

Is there a way to merge several IRelationPredicateBucket objects into a single one?

So if you want to fetch a collection of OrderEntities according to different criterias (Employee, Customer, Product), you could use

myCustomer.GetRelationInfoOrder() myEmployee.GetRelationInfoOrder() myProduct.GetRelationInfoOrderViaOrderDetails()

to form a single IRelationPredicateBucket to use with fetchEntityCollection()

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 26-Oct-2007 23:36:36   

this should work. although the order of relationships is significant so this may be fragile.

function void Merge(IRelationshipBucket source, IRelationshipBucket destination)
{
     foreach(IEntityRelation relation in source.Relationships)
     {
            destination.Relationships.Add(relation);
     }
     foreach(IPredicateExpression predicate in source.PredicateExpression)
     {
            destination.PredicateExpression.Add(predicate);
     }
}

Note: I haven't tested this.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 27-Oct-2007 14:10:03   

dstFilter.Relations.AddRange((RelationCollection)srcFilter.Relations); dstFilter.PredicateExpression.AddWithAnd(srcFilter.PredicateExpression);

Frans Bouma | Lead developer LLBLGen Pro
stefcl
User
Posts: 210
Joined: 23-Jun-2007
# Posted on: 27-Oct-2007 14:31:46   

Thanks Otis and jmeckley, That's exactly the code I wrote, but I was not sure if it was a good practice or not. wink

Just an idea : I think it would be nice to add this to the "How do I..." section of the help?