Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate inner join master-detail on a column other than the id
    text
    copied!<p>Assume the following mapping entries:</p> <p>&lt; class name="Customer" table="customer"></p> <pre><code>&lt;id name="InternalId" column="uintCustomerId" type="long"&gt; &lt;generator class="identity" /&gt; &lt;/id&gt; &lt;!-- The BinaryBlob below is a 16 byte array - Think Guid.NewGuid().ToByteArray --&gt; &lt;property name="CustomerUid" column="uidCustomerId" type="BinaryBlob" not-null="true" /&gt; &lt;property name="Name" column="strFullName" type="String" not-null="true" /&gt; &lt;property name="Age" column="intAge" type="System.Int32" not-null="true" /&gt; &lt;set name="Orders" table="order" generic="true" inverse="false" lazy="false" cascade="all"&gt; &lt;key column="uidCustomerId" /&gt; &lt;one-to-many class="Order" /&gt; &lt;/set&gt; </code></pre> <p></p> <p>&lt; class name="Order" table="order"></p> <pre><code>&lt;id name="InternalId" column="uintOrderId" type="long"&gt; &lt;generator class="identity" /&gt; &lt;/id&gt; &lt;!-- This BinaryBlob is a 16 byte array - Think Guid.NewGuid().ToByteArray --&gt; &lt;property name="CustomerUid" column="uidCustomerId" type="BinaryBlob" not-null="true" /&gt; &lt;property name="OrderDate" column="datOrderDate" type="System.DateTime" not-null="true" /&gt; </code></pre> <p>So there are 2 classes: Customer - Order with properties as defined in the above mapping</p> <p>The Customer PK is uintCustomerId</p> <p>The Order PK is uintOrderId</p> <p>uidCustomerId is a unique key on the Customer table and the fk to Customer on the Order table uidCustomerId is binary(16) </p> <p>The database cannot change. </p> <p>Given the above. How can we query using the NHibernate Criteria API to bring a Customer and his related Orders that are after a given date. NOTE: We need to join on uidCustomerId which is not the primary key. </p> <p>Is this something that can be done with the Criteria API? Is this something that can be done with HQL?</p> <p>Thanks, Tasos</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload