使用 Fluent nhibernate 映射引用的基类
我正在尝试映射一个类层次结构,如下所示:
public abstract class A { }
public class B : A { }
public class C : A { }
我不想映射类 A,因为它是抽象的,我知道我可以这样做:
.IgnoreBase<A>()
不映射 A 并将 A 的所有属性映射到 B 和 C 中。问题是我还有另一个类 D,如下所示:
public class D {
public virtual A a { get; set; }
}
现在,当我尝试使用流畅的 nhibernate 自动映射功能进行映射时,我收到一个错误,类 D 引用未映射的类 A,尽管类 A 实际上是通过子类 B 映射的C.
任何人都知道如何解决 这?
I am trying to map a class hierarchy which looks like this:
public abstract class A { }
public class B : A { }
public class C : A { }
I don't want to map class A because it is abstract, I know I can do:
.IgnoreBase<A>()
to not map A and map all properties of A in B and C. But my problem is that I also have another class D which looks like following:
public class D {
public virtual A a { get; set; }
}
Now, when I try to map with fluent nhibernate auto mapping feature I get an error that class D refers to an unmapped class A, though class A is actually mapped through subclasses B and C.
Anyone know how to solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不映射类 A,则类 B 和 C 将不会是子类。它们只是两个根本没有联系的类。 NHibernate 对 A 类一无所知,那么 NHibernate 如何知道如何处理对 A 类的引用呢?
因为 A 是抽象的所以不映射 A 是没有理由的。您也可以映射接口。
如果您向我们展示您的数据库模型(表),也许您会更清楚您想要做什么。
If you don't map class A the classes B and C won't be subclasses. They are just two classes that are not connected at all. NHibernate knows nothing about class A, so how should NHibernate know how to handle references to class A?
Not mapping A because it's abstract is no reason. You can map interfaces too.
Maybe it would be more clear what you want to do if you show us your DB model (tables).