Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7024933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:54:29+00:00 2026-05-27T23:54:29+00:00

I have a class (Invoice) with a collection (InvoiceRows). Classes – public class Invoice

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:54:29+00:00Added an answer on May 27, 2026 at 11:54 pm

    I managed to find the answer based on Genius answer.

        var dCriteria1 = DetachedCriteria.For<InvoiceRow>("r")
                .SetProjection(Projections.Property("r.RowNumber"))
                .SetProjection(Projections.Property("r.InvoiceID")) // Must be last!!!!
                .Add(Restrictions.Eq("r.RowNumber", 1));
    
        var dCriteria2 = DetachedCriteria.For<InvoiceRow>("r")
                .SetProjection(Projections.Property("r.RowNumber"))
                .SetProjection(Projections.Property("r.InvoiceID")) // Must be last!!!!
                .Add(Restrictions.Eq("r.RowNumber", 2));
    
    
        var invoices = Session.CreateCriteria<Invoice>()
                .Add(Subqueries.PropertyIn("ID", dCriteria1))
                .Add(Subqueries.PropertyIn("ID", dCriteria2))          
                .List<Invoice>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two entity classes: public class Invoice { public int ID { get;
I have class Fred { public: void inspect() const {}; void modify(){}; }; int
So, I have an Invoice object like so: public class Invoice { public virtual
I have some code in a test using Moq: public class Invoice { ...
I have an object Invoice which belongs to an Area: public class Invoice :
So, I have this class: public class Product { private String name, id, info
I have a class, Document and several sub-classes ( Invoice , PurchaseOrder , etc).
I have class method that returns a list of employees that I can iterate
I have class A: public class ClassA<T> Class B derives from A: public class
I have class with internal property: internal virtual StateEnum EnrolmentState { get { ..getter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.