开发者

Using NHibernate's ISession.Get<>() w/ a composite key [duplicate]

开发者 https://www.devze.com 2022-12-20 03:28 出处:网络
This question already has an answer here: nHibernate Composite Key Class Type Mismatch (1 answer) Closed 2 years ago.
This question already has an answer here: nHibernate Composite Key Class Type Mismatch (1 answer) Closed 2 years ago.

I have a composite key in a database table / NHibernate entity. Can I somehow use t开发者_运维知识库he .Get method to grab a specific entity or do I have to use HQL / Criteria due to the composite key?


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'});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号