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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:27:58+00:00 2026-05-20T12:27:58+00:00

I have a problem. I have Persons and Cats. Each Person has some Cats

  • 0

I have a problem. I have Persons and Cats. Each Person has some Cats (there is a foreign key in Cats that points to the primary key in Persons). Each Cat has an Age. I want to select the Persons that have “Old” Cats. I want ALL the Cats of these persons, and not only the “Old” Cats.
I need to do it with the QueryOver syntax.

In T-SQL it would be something like:

SELECT P.*, C.*
FROM Persons P
LEFT JOIN Cats C
    ON P.Id = C.OwnerId
WHERE EXISTS (
    SELECT 1
    FROM Cats C2
    WHERE P.Id = C2.OwnerId AND C2.Age > 5)

I know I have to use the subqueries, and I could to easily with the “old” nhibernate syntax (the Criteria/DetachedCriteria), but I can’t do it in QueryOver syntax.

I DON’T want an “IN” condition. My Primary Key is a complex key, so I can’t do it with the IN.

var persons = session.QueryOver<Person>.WithSubquery.WhereExists( ??? );
  • 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-20T12:27:58+00:00Added an answer on May 20, 2026 at 12:27 pm

    Example taken from this page and adapted (tested with my own classes):

    The trick seems to be using an alias.

    Person personAlias = null;
    
    IList<Person> persons = 
            session.QueryOver<Person>(() => personAlias).WithSubquery
              .WhereExists(QueryOver.Of<Cat>()
                 .Where(c => c.Age > 5)
                 .And(c => c.Owner.Id == personAlias.Id)
                 .Select(c => c.Owner))
              .List<Person>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem that I need to express. There are persons, workplaces
In short, I have an object called PersonList that has a List of Person
Problem: I have a list of names and addresses. Some names (persons) have the
hey, following problem here: i have table with persons that have one location, if
I am have a problem with SQLITE3. I have created 2 tables persons and
Im having rather an annoying problem. I have a class called Person and a
I have a small problem with double-click handling with icefaces. There are two methods
I have a problem with getting some ordering of records and uniqueness. I have
I have the problem that my Faces ActionEvent returns a source, but the check
I have a problem using QBE with NHibernate. Here's a sample code: Person person

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.