I have a composite key in a database table / NHibernate entity. Can I somehow use the .Get
method to grab a specific entity or do I have to use HQL / Criteria due to the composite key?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can only use Session.Get() if you used a key class as suggested here: nHibernate Composite Key Class Type Mismatch
回答2:
With this composite key mapping:
<class name="MyClass">
<composite-id>
<key-property name="Key1" />
<key-property name="Key2" />
</composite-id>
<property name="..." />
</class>
...you can use .Get like this:
var x = Session.Get<MyClass>(new MyClass() { Key1 = 'Foo', Key2 = 'Bar'});