NHibernate 多对一加载替代方案
我有一个 Parent/Child 对象/映射,如下所示:
class Parent {
int Id;
string name;
List<Child> children;
}
<bag name="Children" cascade="all" lazy="false ">
<key column="ParentId" />
<one-to-many class="Child" />
</bag>
class Child {
int Id;
Parent Parent;
string Name;
}
<many-to-one name="Parent" column="ParentId" />
我不想在 Child 中使用属性 Parent Parent
;我想使用int ParentId
。 我将如何绘制它?
I have a Parent/Child object/mapping as follows:
class Parent {
int Id;
string name;
List<Child> children;
}
<bag name="Children" cascade="all" lazy="false ">
<key column="ParentId" />
<one-to-many class="Child" />
</bag>
class Child {
int Id;
Parent Parent;
string Name;
}
<many-to-one name="Parent" column="ParentId" />
I don't want to use the property Parent Parent
in Child; I want to use int ParentId
.
How would I go about mapping that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不需要关联,而只想将 ParentId 作为 Child 类中的 int,则无需映射关联,而是像映射任何其他属性一样映射 ParentId。
另一方面,如果您想要两者,则只需将 Child 中的 ParentId int 属性实现为委托给 Parent.Id 的派生属性(没有映射)。
If you don't want an association, but rather only the ParentId as an int in the Child class, you don't map the association, but instead map the ParentId just as any other property.
If on the other hand you want both, you simple implement the ParentId int property in Child as an derived property (with no mapping) that delegates to Parent.Id.