gpt4 book ai didi

c# - 当映射字段移动到基类时,NHibernate JOIN 映射失败

转载 作者:太空宇宙 更新时间:2023-11-03 12:10:20 25 4
gpt4 key购买 nike

有两个具有许多公共(public)字段的模型类,我决定创建一个基类,并且它们都从它继承。

现有的模型类已经带有 map 类。

现在在子类中继承的所有公共(public)字段都是虚拟的,以使 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
}

现在这些是映射类:

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
}

每当我运行程序,从那些类(表)加载数据时,都会失败,说它在 A 表和 B 表上找不到 TouchGuid 列,这是错误:

enter image description here

是的,A 表和 B 表之间有共同的数据,但我不能更改数据库方案,这会增加太多的复杂性。

我是否也需要为基类创建一个表?如果可能,我想避免创建新表。

有什么可能出错的提示吗?

谢谢!

最佳答案

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

关于c# - 当映射字段移动到基类时,NHibernate JOIN 映射失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52635181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com