[英]Fluent Nhibernate - Mapping two entities to same table
I'm trying to map two domain entities to the same table. 我正在尝试将两个域实体映射到同一张表。 We're doing a smart entity for our domain model, so we have the concept of an Editable Address and a readonly Address.
我们正在为域模型做一个智能实体,因此我们具有可编辑地址和只读地址的概念。 I have both mapped using Classmaps, and everything seems to go fine until we try to export the schema using the SchemaExport class from NHibernate.
我都使用Classmaps进行了映射,直到我们尝试使用NHibernate的SchemaExport类导出架构,一切似乎都很好。 It errors out saying the table already exists.
错误地指出该表已存在。
I assume it's something simple that I'm just not seeing. 我认为这很简单,只是我没有看到。
Any ideas? 有任何想法吗?
Thanks 谢谢
Update 更新资料
There are a couple of other things I didn't mention which I should have. 我没有提到我应该拥有的其他几件事。 I appreicate those that answered so far, but they don't work for us.
到目前为止,我很感激那些回答,但是它们对我们没有用。
One is that we have a single address table, not include the columns in whatever entities have an address. 一种是我们只有一个地址表,在具有地址的任何实体中都不包括列。
The other is that we can't use a common base class. 另一个是我们不能使用通用的基类。 For editable objects, we have a super class which adds validation behaviors to the subclasses.
对于可编辑对象,我们有一个超类,该类将验证行为添加到子类中。 The readonly objects don't need this behavior though and should not have these behaviors.
只读对象虽然不需要这种行为,并且不应具有这些行为。
I have considered an interface, but then I believe I end up in a situtation where you can cast a readonly object to this interface and then changes its values (since presumably NHibernate would use said interface to hydrate the object). 我已经考虑过一个接口,但是我相信我最终会遇到一种情况,您可以在该接口中投射一个只读对象,然后更改其值(因为NHibernate可能会使用该接口来水化该对象)。
So if there's another way to acomplish this, or if mapping via an interface won't have the problem I described, please let me know. 因此,如果还有另一种方法可以完成此操作,或者通过接口映射不会出现我描述的问题,请告诉我。 I'm still learning NHibernate.
我还在学习NHibernate。
Thanks again! 再次感谢!
you can Exclude the readonly class from schemaexport: 您可以从schemaexport中排除只读类:
public class ReadonlyAdressMap : ClassMap<ReadonlyAdress>
{
ReadonlyAdressMap()
{
Schemaaction.None();
[...]
}
}
创建一个基本抽象类实体,稍后将其扩展到“可编辑地址”和“只读地址”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.