NHibernate 中是否有 @MappingSupperclass 等价物

Is there @MappingSupperclass equivalent in NHibernate

我最近以 NHibernate 作为 orm 开始了 Asp Net Core 项目。我对 NHibernate 几乎没有什么经验。 我正在寻找 @MappedSuperclass Hibernate 注释的等效项。要么我找不到好的解决方案,要么我不能使用任何找到的解决方案。 但从一开始: 我的每个实体都继承自基础class BaseEntity,包含几个技术领域/专栏

public class BaseEntity
{
    public virtual long id { get; set; }
    public virtual DateTime inDate { get; set; }
    public virtual DateTime? outDate { get; set; }
    //some other properies
}

public class AnyClass : BaseEntity
{
    //some AnyClass properties
}

public class AnyClassMap : ClassMapping<AnyClass>
{
    public AnyClassMap() 
    {
        Table("any_table");

        //Copy/Paste to each mapping class
        Id(b => b.id, x => { x.Column("id"); x.Generator(Generators.Native); x.Type(NHibernateUtil.Int64); });
        Property(b => b.inDate, x => { x.Column("in_date"); });         
        Version(b => b.outDate, x => { x.Column("out_date"); x.Type(NHibernateUtil.DbTimestamp); });
        //Some other BaseEntity properties

        //some AnyClass properties
    }//ctor
}

在每个映射 class 中,我重复有关基础属性的映射 class。但是,我想实现类似于:

public class BaseEntityMap : MappedSuperclassEquvalent<BaseEntity>
{
    public BaseEntityMap()
    {
        Id(b => b.id, x => { x.Column("id"); x.Generator(Generators.Native); x.Type(NHibernateUtil.Int64); });
        Property(b => b.inDate, x => { x.Column("in_date"); });         
        Version(b => b.outDate, x => { x.Column("out_date"); x.Type(NHibernateUtil.DbTimestamp); });
        //Some other BaseEntity properties
    }//ctor
}

public class AnyClassMap : ClassMapping<AnyClass>
{
    public AnyClassMap() 
    {
        Table("any_table");

        //example only
        IncludeMapping(BaseEntityMap.Class);

        //some AnyClass properties
    }//ctor
}

我知道我可以将 BaseEntity 用作 ComponentMapping,然后在 AnyClass class 中将其用作 属性。 但是,ComponentMapping 不允许 id 和 version 映射。另一方面,出于多种原因,我关心从基础实体继承。

提前致谢

只需根据 ClassMapping 创建基础映射 class,并添加您需要的所有内容:

public class BaseEntityClassMapping<TBaseEntity>: ClassMapping<TBaseEntity> where TBaseEntity: BaseEntity
{
    public BaseEntityClassMapping()
    {
            Id(b => b.id, x => { x.Column("id"); x.Generator(Generators.Native); x.Type(NHibernateUtil.Int64); });
            Property(b => b.inDate, x => { x.Column("in_date"); });
            Version(b => b.outDate, x => { x.Column("out_date"); x.Type(NHibernateUtil.DbTimestamp); });
            //Some other BaseEntity properties
    }
}

并根据此 class:

进行映射
public class AnyClassMap : BaseEntityClassMapping<AnyClass>
{
    public AnyClassMap() 
    {
        Table("any_table");
        //some AnyClass properties
    }
}