Saving two new objects associated by a n-m relationship

Posts   
 
    
Dunebuggy
User
Posts: 8
Joined: 18-Sep-2007
# Posted on: 28-Sep-2007 12:21:04   

Hi,

In my test project i have a n-m association between user and group.

I then execute the follwing code expecting both new objects will be saved.


Dim group as New GroupEntity()
group.Name = "group X"

Dim user as UserEntity = group.Users.AddNew()
user.Name = "user Y"

group.Save(true)


After i check it seems that the group is indeed saved into the database but the user isn't. Can you explain to me why this is not working for an n-m association. It does work for a 1 - n association.

I do understand there is an extra table and thus an extra entity when using a n-m relation. But i expected LLBLGen could handle that.

greets,

Daniƫl

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 28-Sep-2007 16:26:06   

I do understand there is an extra table and thus an extra entity when using a n-m relation. But i expected LLBLGen could handle that.

Nope, LLBLGen doesn't handle the intermediate table, you should handle it. Since the intermediate table can contain more fields than a couple of FKs.

Please check the manual -> Tutorials and examples -> How do I ... ? -> How do I add an entity A to an entity B's collection of A's if A and B have an m:n relation ?