控制 NHibernate 复合元素的唯一性
我有以下映射:
...
<set name="Tests" table="InstrumentTests">
<key column="InstrumentId" />
<composite-element class="InstrumentTest">
<property name="TestInstrumentId" not-null="true" />
<property name="OtherTestId" />
</composite-element>
</set>
我想让 InstrumentId 和 TestInstrumentId 唯一,因此表 InstrumentTest 不能包含:
InstrumentId TestInstrumentId OtherTestId
1 TEST1 ABC
1 TEST1 BCD <--- NO
2 TEST1 ABC <--- OK, different InstrumentId
也许我想要的使用复合元素是不可能的,但是我应该如何映射它。
I have the following mapping:
...
<set name="Tests" table="InstrumentTests">
<key column="InstrumentId" />
<composite-element class="InstrumentTest">
<property name="TestInstrumentId" not-null="true" />
<property name="OtherTestId" />
</composite-element>
</set>
I'd like to make InstrumentId and TestInstrumentId unique so the table InstrumentTest cannot contain:
InstrumentId TestInstrumentId OtherTestId
1 TEST1 ABC
1 TEST1 BCD <--- NO
2 TEST1 ABC <--- OK, different InstrumentId
Maybe what I want is imposible using composite-element, but then how should I map this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我找到了解决方案。我需要为 InstrumentTest 类实现 Equals 和 GetHashCode。
nHiberntate 文档中明确指出:
Ok, I found the solution. I need to implement Equals and GetHashCode for the InstrumentTest class.
It's clearly stated on the nHiberntate documentation: