I have a class (Invoice) with a collection (InvoiceRows).
Classes –
public class Invoice
{
public string ID {get; set;}
public List<InvoiceRow> InvoiceRows {get; set;}
}
public class InvoiceRow
{
public string ID { get; set;}
public string InvoiceID { get; set;}
public int RowNumber { get; set;}
}
Mappings –
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Domain.BusinessClasses.Invoice" table="Invoices" lazy="false">
<id name="ID">
<column name="ID"/>
<generator class="assigned"/>
</id>
<bag name="InvoiceRows" lazy="false" cascade="save-update" inverse="true" order-by="InvoiceRowNumber">
<key column="InvoiceID"/>
<one-to-many class="Domain.BusinessClasses.InvoiceRow" />
</bag>
</class>
<class name="Domain.BusinessClasses.InvoiceRow" table="InvoiceRows" lazy="false">
<id name="ID">
<column name="ID"/>
<generator class="assigned"/>
</id>
<property name="InvoiceID">
<column name="InvoiceID"/>
</property>
<property name="RowNumber">
<column name="RowNumber"/>
</property>
</class>
I want to get all the Invoice objects that have an InvoiceRow with RowNumber = 1 and RowNumber = 2. Preferably with ICriterion API.
I managed to find the answer based on Genius answer.