Iterate through RelationCollection

Posts   
 
    
deepakkb
User
Posts: 2
Joined: 12-Aug-2005
# Posted on: 12-Aug-2005 01:11:46   

I am building a relationPredicatebucket based on user inputs and the query spans across multiple tables. Before adding a particular relation to relationPredicatebucket, I need to somehow iterate through the RelationPredicate.Relations collection to check if the relation already exists. How do I do that?.

Is there any work around for it?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 12-Aug-2005 09:14:43   

Cast RelationPredicate.Relations to RelationCollection: foreach(EntityRelation relation in (RelationCollection)RelationPredicate.Relations)...

or traverse using for, and the indexer: RelationPredicate.Relations[index];

Frans Bouma | Lead developer LLBLGen Pro
deepakkb
User
Posts: 2
Joined: 12-Aug-2005
# Posted on: 12-Aug-2005 18:58:51   

How do I check if a particular relation exists in a relationCollection. I want to add a new relation to the relationcollection only if it does not exist.

Any ideas or work arounds will be great.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 12-Aug-2005 20:44:34   

deepakkb wrote:

How do I check if a particular relation exists in a relationCollection. I want to add a new relation to the relationcollection only if it does not exist.

Any ideas or work arounds will be great.

You can traverse the collection and check each EntityRelation object in the collection, to see if the start/end fields are of the entity type you expect (check ContainingObjectName on a field), and if TypeOfRelation is what you're looking for. If a duplicate relation is added to a relation collection, that's not a problem: both sides are then already in the join list, so the relationcollection will simply skip the relation.

Frans Bouma | Lead developer LLBLGen Pro