NHibernate:使用鉴别器列作为多对一关系

发布于 2024-09-13 05:11:53 字数 753 浏览 2 评论 0原文

我有两张表正在尝试映射。 Table1 通过 FK fk_table2_id 与 Table2 具有多对一关系。

在 table1 的映射中,我还定义了一个鉴别器和一个子类,如下所示:

<class name="MyAssembly.MyClass1, MyAssembly" table="table1" discriminator-value="null">
<discriminator column="fk_table2_id" type="int"/>

<many-to-one name="Category" class="MyAssembly.MyClass2, MyAssembly" column="fk_table2_id"/>

<subclass name="MyAssembly.MyDerivedClass1, MyAssembly" discriminator-value="1"/>

当尝试保存 MyClass1/MyClass2 时,我收到以下错误:

SetUp : System.ArgumentOutOfRangeException : Index was out of range. Must be non-negative and less than the size of the collection.

参数名称:索引

现在我很确定这与我为鉴别器和关系使用一列这一事实有关。这真的是一个限制吗?我该如何解决它?

I've got a two tables that i'm trying to map. Table1 has a many-to-one relationship with Table2 via the FK, fk_table2_id.

In table1's mapping I also have a discriminator and a subclass defined, like so:

<class name="MyAssembly.MyClass1, MyAssembly" table="table1" discriminator-value="null">
<discriminator column="fk_table2_id" type="int"/>

<many-to-one name="Category" class="MyAssembly.MyClass2, MyAssembly" column="fk_table2_id"/>

<subclass name="MyAssembly.MyDerivedClass1, MyAssembly" discriminator-value="1"/>

When trying to save MyClass1/MyClass2, I get the following error:

SetUp : System.ArgumentOutOfRangeException : Index was out of range. Must be non-negative and less than the size of the collection.

Parameter name: index

Now I'm pretty sure it has to do with the fact that I'm using one column for both the discriminator and the relationship. Is this really a limitation? How do I get around it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感情废物 2024-09-20 05:11:54

我想我已经找到了解决方法,以防其他人需要它:

<discriminator type="int" formula="fk_table2_id"/>

I think I got the workaround in case anyone else needs it:

<discriminator type="int" formula="fk_table2_id"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文