Fluent NHibernate:映射列表字典
本文关键字:列表 字典 映射 NHibernate Fluent | 更新日期: 2023-09-27 18:29:01
我有一个DB,其中包含以下表格:
- 角色:[Id,Name,…]
- 权限:[Id,Name,…]
- 元数据定义:[Id,Name,…]
- 角色权限:[Id,RoleId,PermissionId,MetaDataDefinitionId]
POCO类别为:
class Role {
public Role() {
MetaDataPermissions = new Dictionary<MetaDataDefinition, Permission>() ;
}
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual IDictionary<MetaDataDefinition, Permission> MetaDataPermissions { get; set; }
}
class Permission {
public Permission() {
MetaDataRoles = new Dictionary<MetaDataDefinition, Role>() ;
}
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual IDictionary<Role, MetaData> RolesMetaData { get; set; }
}
class MetaData {
public MetaData() {
RolePermissions = new Dictionary<Role, Permission>() ;
}
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual IDictionary<Role, Permission> RolePermissions { get; set; }
}
Fluent映射:
class RoleMap : ClassMap<Role> {
public RoleMap() {
[...]
HasManyToMany( x => x.MetaDataPermissions )
.Table( "RolePermissions" )
.AsEntityMap( "MetaDataDefinitionId", "PermissionId" )
.KeyColumn( "RoleId" ) ;
[...]
}
}
class PermissionMap : ClassMap<Permission> {
public PermissionMap() {
[...]
HasManyToMany( x => x.RolesMetaData )
.Table( "RolePermissions" )
.AsEntityMap( "RoleId", "MetaDataDefinitionId" )
.KeyColumn( "PermissionId" ) ;
[...]
}
}
class MetaDataMap : ClassMap<MetaData> {
public MetaDataMap() {
[...]
HasManyToMany( x => x.RolePermissions )
.Table( "RolePermissions" )
.AsEntityMap( "RoleId", "PermissionId" )
.KeyColumn( "MetaDataDefinitionId" ) ;
[...]
}
}
但在POCO课程中,我需要这个:
public virtual IDictionary<Role, IList<MetaData>> RolesMetaData { get; set; }
这样的字典应该如何在映射中表示?