NHibernate:使用鉴别器列作为多对一关系
我有两张表正在尝试映射。 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我已经找到了解决方法,以防其他人需要它:
I think I got the workaround in case anyone else needs it: