开发者

Fluent nHibernate Mapping issue

I have a DB with the following tables

  • Users
  • Roles
  • UserInRoles (Bridge table for Users and Roles for many to many relationship
  • Modules
  • ModulePermission (this include the PK of Roles and modules and a bool field to identify the role has permission to access the module or not

now i m confuse about the Mapping of these table in fluent nHibernate, i did the mapping as define in Fluent nHibernate Wiki site but getting this error:

(XmlDocument)(3,6): XML validation error: The element 'composite-id' in namespace 'urn:nhibernate-mapping-2.2' has incomplete content. List of possible elements expected: 'meta, key-property, key-many-to-one' in namespace 'urn:nhibernate-mapping-2.2'.

Mapping: UserMap:

public class UserMap : ClassMap<User>
{
    public UserMap()
    {
        Table("tblUsers");
        LazyLoad();
        Id(user => user.UserID).GeneratedBy.GuidComb();
        Map(user => user.UserName).Not.Nullable();
        Map(user => user.Password).Not.Nullable();
        Map(user => user.IsActive).Nullable();
        HasManyToMany(user => user.RolesOfUser).Cascade.All().Inverse().Table("UserInRoles");
    }
}

RoleMap:

public class RoleMap : ClassMap<Role>
{
    public RoleMap()
    {
        Table("tblRoles");
        Id(role => role.RoleID).GeneratedBy.Identity(开发者_如何学Python);
        Map(role => role.RoleName).Not.Nullable();
        Map(role => role.IsActive).Not.Nullable();
        Map(role => role.Description).Not.Nullable();
        HasManyToMany(role => role.Users).Cascade.All().Table("UserInRoles");
    }
}

Does anyone know what is the issue?

Thanks


HasManyToMany mapping configuration worked for me when I defined Parent and Child Key Column. You can do it like this:

HasManyToMany(user => user.RolesOfUser)
    .Table("UserInRoles")
    .ParentKeyColumn("UserID")
    .ChildKeyColumn("RoleID");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜