Note that there are some explanatory texts on larger screens.

plurals
  1. POnhibernate criteria for selecting from different tables
    primarykey
    data
    text
    <p>I have following table model:</p> <p><img src="https://i.stack.imgur.com/KBmIx.png" alt="enter image description here"></p> <p>I want following SQL command as nhibernate criteria:</p> <blockquote> <p>SELECT * FROM Units WHERE OID IN (SELECT OID FROM Orders WHERE PONumber &lt;> 0 ORDER BY PONumber LIMIT 5)</p> </blockquote> <p>-> in other words: the last 5 orders</p> <p>EDIT:</p> <p>my mappings</p> <p>Unit.hbm.xml</p> <pre><code>&lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DCGOrderSystem" namespace="DCGOrderSystem.Model"&gt; &lt;class name="Unit" table="Units"&gt; &lt;id name="ID"&gt; &lt;column name="UID" /&gt; &lt;generator class="native" /&gt; &lt;/id&gt; &lt;property name="Division" /&gt; &lt;property name="Date" /&gt; &lt;property name="ItemOrderNr" /&gt; &lt;property name="Description" /&gt; &lt;property name="Amount" /&gt; &lt;property name="Price" /&gt; &lt;property name="CostCenter" /&gt; &lt;property name="Location" /&gt; &lt;property name="DeviceGroup" /&gt; &lt;property name="Comment" /&gt; &lt;property name="Distributor" /&gt; &lt;!-- Many-to-one mapping: Employee --&gt; &lt;many-to-one name="EmployeeRef" column="EID" cascade="all" /&gt; &lt;!-- Many-to-one mapping: Order --&gt; &lt;many-to-one name="OrderRef" column="OID" cascade="all" /&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>Order.hbm.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DCGOrderSystem" namespace="DCGOrderSystem.Model"&gt; &lt;class name="Order" table="Orders"&gt; &lt;id name="ID"&gt; &lt;column name="OID" /&gt; &lt;generator class="native" /&gt; &lt;/id&gt; &lt;property name="Locked" /&gt; &lt;property name="PONumber" /&gt; &lt;!-- One-to-many mapping: Units --&gt; &lt;bag name="Units" cascade="all" lazy="true"&gt; &lt;key column="OID" /&gt; &lt;one-to-many class="Unit" /&gt; &lt;/bag&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>Employee.hbm.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DCGOrderSystem" namespace="DCGOrderSystem.Model"&gt; &lt;class name="Employee" table="Employees"&gt; &lt;id name="ID"&gt; &lt;column name="EID" /&gt; &lt;generator class="native" /&gt; &lt;/id&gt; &lt;property name="Name" /&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>EDIT2:</p> <p>Here my query command:</p> <pre><code>var query = m_hibernateSession.QueryOver&lt;Model.Order&gt;(() =&gt; orderAlias) .JoinAlias(() =&gt; orderAlias.ID, () =&gt; unitAlias, JoinType.InnerJoin) .TransformUsing(Transformers.DistinctRootEntity) .OrderBy(x =&gt; x.PONumber).Desc.Take(5); </code></pre> <p>Thx</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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