Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 435
David Pfeffer Avatar asked Feb 16 '10 17:02

David Pfeffer


1 Answers

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'});
like image 71
Christian Specht Avatar answered Oct 07 '22 18:10

Christian Specht