Databinding and many to many relationships

Posts   
 
    
jaschag
User
Posts: 79
Joined: 19-Apr-2006
# Posted on: 03-Oct-2006 20:53:44   

What is the approaches do you use to provide an interface to edit m:n data? Particularly where the "n" entity (as in m:n) needs to be created as well as the link entity? How about deletions?

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 04-Oct-2006 02:25:58   

Well it can vary on how the M:N relationship is created. When speaking of a simple link table like you suggest creating a new N entity related to an M entity is not difficult.

Create a new LinkEntity and NEntity. Then set the MEntity.LinkEntity property to the LinkEntity and set the NEntity.LinkEntity property to the LinkEntity. Now you should be able to save the NEntity recursively and it will save all three entites and set the proper PK:FK in all three entities. If you have any issues just let us know.

jaschag
User
Posts: 79
Joined: 19-Apr-2006
# Posted on: 04-Oct-2006 12:11:40   

bclubb wrote:

Well it can vary on how the M:N relationship is created. When speaking of a simple link table like you suggest creating a new N entity related to an M entity is not difficult.

Create a new LinkEntity and NEntity. Then set the MEntity.LinkEntity property to the LinkEntity and set the NEntity.LinkEntity property to the LinkEntity. Now you should be able to save the NEntity recursively and it will save all three entites and set the proper PK:FK in all three entities. If you have any issues just let us know.

Yes, I am referring to a simple link table in this case. I guess the issue that I am trying to clarify is what style of interface people use to represent this and how that would be achieved with LLBLGen. For example, if you have entity A relating m:n to entity B via link table AB, a simple interface might be to have a form for entity A with a detail grid for all entity B's belonging to A. For the grid to be editable, the grid would need to be bound to the property on A that holds the relation to the class AB so additional logic would be needed to manage the linking to / creation of B enitites. Have you / anyone created this the kind of interface? Are there any tricks to doing this or alternatives?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 04-Oct-2006 16:09:18   

a simple interface might be to have a form for entity A with a detail grid for all entity B's belonging to A. For the grid to be editable

Exactly, then what you need to do in your code-behind or BL: When Inserting: create the AB entity and assign it to the B Entity and save them recursivley When Deleting: make sure you use a transaction to delete the AB entity first then the B entity itself.