当映射字段移动到基 class 时,NHibernate JOIN 映射失败

NHibernate JOIN mapping fails when the mapped field is moved to a base class

有两个模型 classes 有很多公共字段,我决定创建一个基础 class 并且它们都从它继承。

现有模型 classes 已经带有地图 classes.

现在在子 classes 中继承的所有公共字段都是虚拟的,以使 NHibernate 满意并且它们都映射正常,除了一个...

这是我的情况:

public class BaseClass : EntityBase<Guid>
{
   //This is not complaining 
   public virtual string Text { get; set; }

   //This is complaining
   public virtual Guid TouchGuid { get; set; }
}

public class A : BaseClass
{
    //inherited + specific stuff
}

public class B : BaseClass
{
    //inherited + specific stuff
}

现在这些是映射 classes:

public class AMap : ClassMapping<A>
{
    //Mapping the ID inherited from EntityBase class
    Id(x => x.Id, mapper =>
    {
        mapper.Generator(Generators.GuidComb);
        mapper.Column("Pk_MenuItemId");
    });

    //Mapping the common field inherited, doesn't complain !
    Property(x => x.Mnemonic);

    //This is the one which is complaining, keep in mind it was working
    //before creating the base class and move the TouchGuid property in it.
    Join("Touch", x =>
    {
        x.Key(k =>
        {
            k.Column("EntityId");
            k.ForeignKey("PK_AClassId");
            k.OnDelete(OnDeleteAction.Cascade);
            k.Unique(true);
        });
        x.Property(p => p.TouchGuid);
    });
}

public class BMap : ClassMapping<B>
{
    //Same map as for class A
}

每当我 运行 程序从那些 classes (tables) 加载数据时,都会失败,说它找不到 A 上的 TouchGuid 列 table分别为Btable,这里是错误:

是的,A 和 B tables 之间有公共数据,但我无法更改数据库方案,现在它会增加太多复杂性。

我是否也需要为基础 class 创建一个 table?如果可能的话,我想避免创建一个新的 table。

任何可能出错的提示?

谢谢!

我相信 NHibernate 假设一个包含多个表的数据库模式,因为它默认为隐式多态模式。尝试在映射中设置 polymorphism=explicit。