I have a DB with the following tables:
POCO classes are:
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 mappings:
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" ) ;
[...]
}
}
But in POCO classes i need this:
public virtual IDictionary<Role, IList<MetaData>> RolesMetaData { get; set; }
How such dictionaries should be represented in the mapping?
Directly mapping a dictionary of lists is not supported.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With