Saving m:n relation

Posts   
 
    
Posts: 19
Joined: 03-Feb-2006
# Posted on: 07-Feb-2006 14:11:55   

Hajo,

I've been trying to save m:n for last 2 hours but I can't find out how to do this? I have simple User and Role situation. User can be in many roles and one role can be assigned to many user. At the moment my code looks like that (SelfServicing):



        Role role = new Role();
        role.Name = textBoxRoleName.Text;
        

        User user = DAL.DataClasses.User.FindByName("user1");
        user.Roles.Add(role);

        user.Save(true);



It saves role object but junction table (UserRoles) is empty. It seems that I can't store anything about relation between User and Role object?

thanks

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 07-Feb-2006 14:28:37   

Please check the LLBLGen Pro documentation and read the following Q & A "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 ?"

You can find it under "Best practises - How do I ... ?"

Posts: 19
Joined: 03-Feb-2006
# Posted on: 07-Feb-2006 15:18:02   

Sorry, I am blind rage .