gpt4 book ai didi

c# - NHibernate 多对一还是我遗漏了什么?

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

我已经研究 NHibernate 3.2 一段时间了,我想要实现的是我认为应该相对简单但似乎找不到代码示例的东西。

我只想拥有 2 个对象。

public class ObjectA { 
public int Id;
public string PropertyA;
public ObjectB PropertyB;
}

public class ObjectB {
public int Id;
public string PropertyA;
}

在数据库方面我想要

----
Table ObjectA
----
Column Id
Column PropertyA
Column ObjectBId
----

----
Table ObjectB
----
Column Id
Column PropertyA
----

我似乎无法让它工作,但它应该是微不足道的。我试过使用组件,但他们似乎只想创建一个表,其中包含 ObjectA 和 ObjectB 的所有字段。我试过使用一对一映射,但它希望我通过将 ObjectB 中的引用属性返回到 ObjectA 来破坏我的对象模型。

最佳答案

这是一个非常简单的案例:

<class name="ObjectA">
<id name="Id" access="property">
<generator class="identity" />
</id>

<property name="PropertyA" />
<many-to-one name="PropertyB" column="ObjectBId" class="ObjectB" />
</class>

<class name="ObjectB">
<id name="Id" access="property">
<generator class="identity" />
</id>

<property name="PropertyA" />
</class>

关于c# - NHibernate 多对一还是我遗漏了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8907681/

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