How to m:n data bind

Posts   
 
    
timt
User
Posts: 14
Joined: 13-Nov-2006
# Posted on: 25-Feb-2008 08:49:35   

Hi

what would be the best way to handle a m:n relationship when using databinding on a aspx page? As I understand you can only databind to a single class. Would I need to create a new class inheriting from User and adding a bit of UserRole?

For example I have a User,Role and UserRole Entities, the UserRole Entity linking the User and Role Entities. I add my UserEntity to a page and can databind the fields. I also want to add the RoleID from the UserRole Entity so the user can assign a role when creating a user (Im using a formview). So that when saved the UserEntity is saved and the UserRoleEntity is also saved pulling in the UserID from the just saved UserEntity and the RoleID from the page?

Thanks Tim

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Feb-2008 10:25:02   

A user can have many roles (hence the m:n relation) From a UI point of view you should use another Data bound control like 2 listViews to assign roles to a user, or just one listView where the selected items are assigned to a user.

If you want to have this inside the FormView, then you should set LivePersistence to false and manually handle the saving of UserRoles along with the User data.

timt
User
Posts: 14
Joined: 13-Nov-2006
# Posted on: 25-Feb-2008 13:33:09   

Ok, lets assume another scenario, I have a 1:1 mapping for 2 entities and I want to combine them onto a single page, single formview with databinding. I effectively want to bind to a single entity(made up of 2 related entities).

If I could nest the datview or formview that might work with 2 datsources else I have to have 2 separate unnested controls which I dont want as I want to be able to mix the field positions.

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 25-Feb-2008 18:35:53   

timt wrote:

Ok, lets assume another scenario, I have a 1:1 mapping for 2 entities and I want to combine them onto a single page, single formview with databinding. I effectively want to bind to a single entity(made up of 2 related entities).

If you have a 1:1 rel, this often is candidate for inheritance.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39905
Joined: 17-Aug-2003
# Posted on: 26-Feb-2008 10:16:15   

(if the 1:1 relation is pk-pk. )

Frans Bouma | Lead developer LLBLGen Pro