Inverse relationship search (lpt)

Posts   
 
    
MatthewM
User
Posts: 78
Joined: 26-Jul-2006
# Posted on: 21-Sep-2006 22:17:32   

I needed to find the inverse (1:n) matching relationships of an entities parent's (m:1) ...I think steam came out of my ears on this one smile , but here it is:

for (int f = 0;f < e.Relations.Count;f++)
{
    if (e.Relations[f].RelationType == EntityRelationType.ManyToOne)
    {
        for (int g = 0;g < e.Relations[f].RelationEndPoint.Relations.Count;g++)
        {
            if (e.Relations[f].RelationEndPoint.Relations[g].RelationEndName == e.Relations[f].RelationStartName && e.Relations[f].RelationEndPoint.Relations[g].RelationType == EntityRelationType.OneToMany)
            {
                ParentsChildRelation = e.Relations[f].RelationEndPoint.Relations[g];
                break;
            }
        }
    
        // Do something
    }
}

If there is a simpler solution, I'd love to know for grins. sunglasses

Edit: If you want to know why on earth...I'll answer wink

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 21-Sep-2006 22:55:10   

EntityRelation.CreateMirroredCopy() wink

then simply do a Contains check simple_smile

Frans Bouma | Lead developer LLBLGen Pro
MatthewM
User
Posts: 78
Joined: 26-Jul-2006
# Posted on: 21-Sep-2006 22:55:45   

Otis wrote:

EntityRelation.CreateMirroredCopy() wink

then simply do a Contains check simple_smile

Oh now that is PAINFUL! I'm not sure I wanted to know now..I'm not surprised it exists as that would be a necessary feature. I am more and more amazed at how solid this product is. Having the whole API available for generating templates is just too cool.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 22-Sep-2006 15:07:08   

MatthewM wrote:

Otis wrote:

EntityRelation.CreateMirroredCopy() wink

then simply do a Contains check simple_smile

Oh now that is PAINFUL! I'm not sure I wanted to know now..I'm not surprised it exists as that would be a necessary feature.

I use it a lot internally, so it was a necessary method simple_smile

I am more and more amazed at how solid this product is. Having the whole API available for generating templates is just too cool.

Thanks! smile

Frans Bouma | Lead developer LLBLGen Pro