使用带有复合键的 NHibernate 的 ISession.Get<>() [英] Using NHibernate's ISession.Get<>() w/ a composite key
本文介绍了使用带有复合键的 NHibernate 的 ISession.Get<>()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在数据库表/NHibernate 实体中有一个复合键.我可以以某种方式使用 .Get
方法来获取特定实体,还是由于复合键而必须使用 HQL/Criteria?
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?
推荐答案
使用这个复合键映射:
<class name="MyClass">
<composite-id>
<key-property name="Key1" />
<key-property name="Key2" />
</composite-id>
<property name="..." />
</class>
...你可以使用 .Get 像这样:
...you can use .Get like this:
var x = Session.Get<MyClass>(new MyClass() { Key1 = 'Foo', Key2 = 'Bar'});
这篇关于使用带有复合键的 NHibernate 的 ISession.Get<>()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文