M:N relation with entries from the same table

Posts   
 
    
Sokon1
User
Posts: 97
Joined: 17-Jul-2006
# Posted on: 28-Nov-2006 11:41:32   

I have an table A which is a link table with two foreign keys linked to the same table B. Now i've got an entity from table B and want to access ist M:N-linked 'table-B-entities'-collection. This should be possible with a GetMulti...viaTableA()-Method, I think. (self servicing, C#)

LLBLGen doesn't create this M:N relation by itself. I found out that i can model this relation be adding table B for a second time in the designer. Is this the only possibility to do this? It seems to me, that my idea is just a dirty workaround. For example, as a result, there are two M:N collections - dirty wink

Thanks again for hints!

(Edited to avoid confusion for others reading this, the next few posts refer to former mistakes in the explanation)

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 28-Nov-2006 15:19:21   

Hello,

if I understand the A Entity is only an entity used to link 2 B Entity like this: A----B1 ----B2

Is you A entity get a PK or is the 2 FK are PK ? So why don't you need to start from A entity? From B entity, you will get a linked B entity collections directly.

Sokon1
User
Posts: 97
Joined: 17-Jul-2006
# Posted on: 28-Nov-2006 15:53:30   

Oh sorry, my mistake. I've got a B-Entity and want to get the linked B-entities. But I don't get the collection directly.

P.S. I corrected my post above.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 29-Nov-2006 07:37:24   

Your initial post is a little bit confusing, would you re-read it to check the validity of the As and Bs within the post?

Hints: 1- GetMulti...viaTableB()- (if I'm understanding correctly, shouldn't this be viaTableA?) 2- I found out that i can model this relation be adding table A for a second time in the designer (do you mean adding Table B for a second time?)

Sokon1
User
Posts: 97
Joined: 17-Jul-2006
# Posted on: 29-Nov-2006 09:22:58   

simple_smile Sorry for the confusion. I should have read my first post more carefully when I tried to correct it. I try to explain again:

Two Tables:

  • table_A (via/link table): lngPk_A, lngFk_B1, lngFk_B2

  • table_B: lngPk_B

table_A is indeed an via(=link) table. The GetMultiVia...tableA()-method is not created by LLBLGen. To force the creation of it I tried re-adding table_B in the designer (result is a entity named table_b_). And yes, I added table_B for a second time.

P.S.: (Tried to) correct my first post.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 29-Nov-2006 10:01:59   

An M:N relation with self isn't supported, as that will potentially give a lot of (unwanted) m:n relations and it's also not efficient as you can use 2 tables while the generated code will use 3 (start, intermediate and end and start and end are the same entity. )

You can of course add the entity twice and use that, though I'd simply use a fetch in a separate collection instead, as the m:n collection is readonly anyway.

Frans Bouma | Lead developer LLBLGen Pro