views:

331

answers:

1

Hi, i have the following code, which is supposed to give specific functionality but it isn't :S

anyway, here's my problem:

http://img525.imageshack.us/img525/1315/diagramp.png

here's the mapping code:

public class UsersMap : ClassMap<User>
{
    public UsersMap()
    {

        this.Table("Users");
        Id(x => x.UserName).GeneratedBy.Assigned();

        Map(x => x.FirstName);
        Map(x => x.LastName);
        Map(x => x.Password);
        Map(x =>x.EMail);
        Map(x => x.Title);
        Map(x => x.Division);
        Map(x => x.Status);

        HasManyToMany(x => x.Roles)
            .Table("UserInRoles").ParentKeyColumn("Username")
            .ChildKeyColumn("RoleId").AsBag().Inverse();


    }
}

public class RolesMap : ClassMap<Role>
{

    public RolesMap()
    {
        this.Table("Roles");
        Id(x => x.ID).GeneratedBy.Assigned();
        Map(x => x.RoleName);

        HasManyToMany(x => x.Users)
            .Table("UserInRoles").ParentKeyColumn("RoleId")
            .ChildKeyColumn("Username").AsBag().Cascade.All();

    }


}

my problem is when trying to (assign a Role for specific user) the UserName is added to table UserInRoles but the Role ID if it is already existing it will be removed from its corrosponding row and assigned to the new row, any idea ?

+1  A: 

Have you looked making your ManyToMany work by convention?

Linked example actually refers to Roles and pretty much what you are trying to do here.

dove
Thank you, but it seems the same issue after making some changes ( as in the link you posted).
Saeedouv

related questions