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 9040571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:01:10+00:00 2026-06-16T10:01:10+00:00

have a class structure like so Permit -> Financial ->ICollection instrumentList Instrument -> Agency

  • 0

have a class structure like so
Permit -> Financial ->ICollection instrumentList
Instrument -> Agency

That is, an instance of Permit contains an instance of Financial
An instance of Financial has a collection of Instrument objects
An instance of Instrument has an Agency

Using NHibernate Critieria, I want to get a list of Permits with Instruments of a certain type of Agency
This code, gets all Permits with Financial info (it may be the case the a Permit does not have Financial info, in which case I don’t need it)

// get all all Permits with Financial info
var financialCriteria = DetachedCriteria.For<Financial>()
       .SetProjection(Projections.Property("Permit.Id")); // Permit.Id in Select 

queryCriteria.Add(Subqueries.PropertyIn("Id", financialCriteria)); // Permit.Id in Select

Then I want to restrict that list to Agency of a types 2 & 3:

// then restrict to certain Agency types
var instrumentCriteria = DetachedCriteria.For<Instrument>()
    .SetProjection(Projections.Property("Id")) // Instrument.Id in Select
    .Add(Restrictions.In("Agency", new object[] { 2, 3})); // Where

queryCriteria.Add(Subqueries.PropertyIn("Id", instrumentCriteria)); //

However, when running with the 2nd chunk of code, I get back an empty list when I know there are 2s and 3s.

What I am doing wrong?

  • 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-06-16T10:01:12+00:00Added an answer on June 16, 2026 at 10:01 am

    If I do understand your scenario correclty, then the instrumentCriteria returns the list of Instrument ID. So with this list we should not limit the queryCriteria but the financialCriteria. So try this:

    financialCriteria.Add(Subqueries.PropertyIn("Id", instrumentCriteria)); 
    

    Instead of queryCriteria.Add(Subqueries.PropertyIn(“Id”, instrumentCriteria));

    And the result (projection) of the instrumentCriteria should be the owning Financial ID:

    var instrumentCriteria = DetachedCriteria.For<Instrument>()
        .SetProjection(Projections.Property("Financial.Id")) // owner ID
    

    EDIT:

    In case, that Instrument could reference Financial, or at least has property FinancialId, the syntax returning Permit, filtered by Agency will look like this:

    var instrumentCriteria = DetachedCriteria.For<Instrument>()
        // I. Financial as a reference
        .SetProjection(Projections.Property("Financial.ID")) 
        // II. or just a int property FinancialId
        // .SetProjection(Projections.Property("FinancialId")) 
        .Add(Restrictions.In("Agency.ID", new object[] { 2, 3 })); // Where
    
    var financialCriteria = DetachedCriteria.For<Financial>()
        .SetProjection(Projections.Property("ID")) // the ID of instrument
        .Add(Subqueries.PropertyIn("ID", instrumentCriteria));
    
    var queryCriteria = session.CreateCriteria<Permit>()
        .Add(Subqueries.PropertyIn("Financial.ID", financialCriteria));
    
    var result = queryCriteria.List<Permit>();
    Assert.IsTrue(result.Any());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that has structure like this (td omitted) <table> <tr class=header>...</tr>
I have a hierarchical class structure like this: Category -> Template -> Instance A
I have a class structure that looks like this: class Person { public virtual
I have a class structure like class A: def method1(self): return 1 class B:
I have a class structure like abstract class Animal { public Animal(){ //init stuff..
I have a class structure like: abstract class A { String a; } class
Say I have a structure like: class SomeObject Public Name as String Public Created
I have a files structure like this: Class (folder): - User.php - Rule.php Scripts
I have got the following class structure, and have plenty of classes like C
I have a class structure which looks like: class TestResults { public bool IsSuccess;

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.