Define Many To Many Relations

Posts   
 
    
chrissie
User
Posts: 84
Joined: 05-Oct-2010
# Posted on: 23-May-2011 17:34:44   

Hi,

I use Ms Windows 7 SP 1, MS SQL Server 2008 R 2, MS VS 2010 SP 1, C# 4, .Net Framework 4, EF 4, LLBLGen Pro 3,1 (first release of 3.1).

I have two entity definitions A and B. Both contain the pk attribute [ROWID] of type [GUID]. Entiy A has as an additional attribute the attribute [NAME] of type [STRING(50)], the entity B has as an additional attribute the attribute [BIRTHDAY of type [DATETIME]. When I now want to define a MANY-TO-MANY relationship starting with entity A I get a dialog with entity A predefined, thats it (I see no possibility to select entity B as part of MANY-TO-MANY relationship to be defined).

QUESTION: How can I define a MANY-TO-MANY relationship in the designer?

Thanx in advance,

regards

Chris

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 24-May-2011 06:14:56   

Hi Chris,

Why do you want m:n relation? An m:n relation requires an intermediate table. Your tables A and B are candidates for a normal 1:1 relation, which seems to be the natural way there were designed for.

David Elizondo | LLBLGen Support Team
chrissie
User
Posts: 84
Joined: 05-Oct-2010
# Posted on: 24-May-2011 11:09:00   

Hi David,

first of all, thanx for answering.

I tried to make an example as simple as possible, hoping to get the answer on the first run. Unfortunately it did not work. Ok, here we go:

I have an entity called PEOPLE and an entity called BOTTLEWINE. Now it might happen, that four people share one bottle of wine or it might happen that a lonesome man drinks three bottle of wine.

In the entity designer of ef 4 i would now define two entities called PEOPLE and BOTTLEWINE. After that I would define a relationship between those entities of cardinality * of both side. That's it.

My question is:

What do I have to do in LLBLGen Pro 3.1 to define a MANY-TO-MANY relationship between such two entities the same way I can do it in the ef 4 designer? If I try it, I can not select the second entity, only the first one.

Thanx in advance,

regards

Chris

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 24-May-2011 11:51:59   

The Intermediate Entity have to be there, and 1-m m-1 relations should be established. Before you can add Many to many relations between end entities.

chrissie
User
Posts: 84
Joined: 05-Oct-2010
# Posted on: 24-May-2011 11:54:23   

Hi,

Thanx for the answer and I understand, what I have to do.

But is there an explanation why LLBLGen has another behaviour in this point as entity framework has?

regards

Chris

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 24-May-2011 13:56:38   

chrissie wrote:

Hi,

Thanx for the answer and I understand, what I have to do.

But is there an explanation why LLBLGen has another behaviour in this point as entity framework has?

regards

Chris

The intermediate entity always has to be there to be predictable. When you add a new property to the intermediate entity, it will suddenly become a real entity, and persisting the m:n relationship changes everywhere in your code. For frameworks which support hidden intermediate entities (EF only supports these btw) we skip the intermediate entity if it's a pure intermediate entity (only pk fields).

Hope this helps wink

Frans Bouma | Lead developer LLBLGen Pro
chrissie
User
Posts: 84
Joined: 05-Oct-2010
# Posted on: 24-May-2011 16:42:02   

Hi Otis,

thank you very much for the explanation.

regards

Chris