Closed Elvin1492 closed 4 years ago
Because of the issue with fluent-nhibernate, it seems joined-subclass
mapping is not supported by FluentNHibernate now.
NHibernate.AspNetCore.Identity
's classes , please refer to the exists hbm mappings;*.hbm.xml
files , don't use FluentHiberate;joined-subclass
mapping with the existing hbm xml mapping , which I have tested with it before。 Personaly, I prefer to use xml mapping (*.hbm.xml), because both
FluentHiberate
andNHibernate.Mapping.Attributes
will translate it's mapping to xml mapping at runtime. And with the help of NHibernate's xml schema (nhibernate-configuration.xsd and nhibernate-mapping.xsd) file, editing hbm file with intelli popup is easy too.
For more details, please refer to issue #10 .
@beginor have you tried using Nhibernate.Mapping.ByCode? Have the "root entity for AppRole was never registered" MappingException even when using JoinedSubclassMapping
@marcelNgan I have already developed fluent-mapping for identity. You can find it in this repo. @beginor , if you want I can create PR for it in here.
@Elvin1492 Thanks, but I do not use fluent-mapping
because of https://github.com/nhibernate/NHibernate.AspNetCore.Identity/issues/13#issuecomment-546645665
@marcelNgan I will try using this library with NHibernate.Mapping.ByCode
, But I think it should be the same as NHibernate.Mapping.Attributes
, which I had test before.
@marcelNgan If you are using with NHibernate.Mapping.ByCode
, please start with rewriting of AppRole.hbm.xml
and like this :
using NHibernate;
using NHibernate.Type;
using NHibernate.Mapping.ByCode.Conformist;
using NHIdentityRole = NHibernate.AspNetCore.Identity.IdentityRole;
namespace WebTest.Entities {
public class AppRoleMapping : JoinedSubclassMapping<AppRole> {
public AppRoleMapping() {
// Add NHIdentityRole as root entity first
ExplicitDeclarationsHolder.AddAsRootEntity(typeof(NHIdentityRole));
Extends(typeof(NHIdentityRole));
Schema("public");
Table("app_roles");
Key(k => k.Column("id"));
Property(
p => p.Description,
maping => {
maping.Column("description");
maping.Type(NHibernateUtil.String);
maping.Length(256);
}
);
}
}
}
Then compile the mapping and add them after AddIdentityMappings
in Startup.cs
var cfg = new Configuration();
var file = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
"hibernate.config"
);
cfg.Configure(file);
// Add identity mapping based on dialect config (dialet must contains
// PostgreSQL, MySQL or MsSql)
cfg.AddIdentityMappings();
// cfg.AddAssembly(typeof(Startup).Assembly);
var modelMapper = new NHibernate.Mapping.ByCode.ModelMapper();
modelMapper.AddMapping<AppRoleMapping>();
modelMapper.AddMapping<AppUserMapping>();
modelMapper.AddMapping<TodoItemMapping>();
var mappings = modelMapper.CompileMappingForAllExplicitlyAddedEntities();
cfg.AddMapping(mappings);
@Elvin1492 I think the project offluent-mapping
is obsoleted, does not have any update for more then one year.
if you are interested in using of NHibernate.Mapping.ByCode
, please keep track of #16 , I will refact to use NHibernate.Mapping.ByCode
.
I am getting this issue when trying to add role to user I am using fluent mapping as follow, table was successfully created. Also the user and the role is in database already. So they were created successfully.