我有以下代码,它应该提供特定的功能,但它不是:S
无论如何,这是我的问题:
http://img525.imageshack.us/img525/1315/diagramp.png
这是映射代码:
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();
}
}
我的问题是在尝试(为特定用户分配角色)时,UserName被添加到表UserInRoles但是如果角色ID已经存在,它将从其相应的行中删除并分配给新行,任何想法?