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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:35:05+00:00 2026-05-16T17:35:05+00:00

I have this problem: When I try to implement Ayende’s complex searching found at:

  • 0

I have this problem:
When I try to implement Ayende’s complex searching found at:
http://ayende.com/Blog/archive/2006/12/07/ComplexSearchingQueryingWithNHibernate.aspx
with the object graph:
Person:
M:1 Address:
M:1 Street:
M:1 Place:
M:1
Country
I get the following error: NHibernate.QueryException: Cannot use
subqueries on a criteria without a projection.
I am doing this:

public List<Person> Find() 
{ 
    DetachedCriteria query = DetachedCriteria.For<Person>(); 
    AddAddressQuery(query); 
    return personRepository.Find(query);
} 

private void AddAddressQuery(DetachedCriteria query) 
{ 
     DetachedCriteria addressQuery = null; 
     if (!String.IsNullOrEmpty(SearchParams.HouseNumer)) 
     { 
         addresaQuery = DetachedCriteria.For<Address>(); 
         addresaQuery.Add(Restrictions.Eq("HouseNumer", 
SearchParams.HouseNumer)); 
     } 
     this.AddStreetQuery(ref addressQuery); 
     if (addressQuery != null) 
     { 
         query.CreateCriteria("Address1", 
"address1").Add(Subqueries.Exists(addressQuery)); 
     } 
} 

private void AddStreetQuery(ref DetachedCriteria query) 
{ 
    DetachedCriteria streetQuery = null; 
    if (this.SearchParams.StreetId.HasValue) 
    { 
        streetQuery = DetachedCriteria.For<Street>(); 
        streetQuery .Add( Restrictions.Eq("Id", 
this.SearchParams.StreetId.Value)); 
    } 
    if (streetQuery != null) 
    { 
        query = query ?? Query.CreateCriteria("Address1"); 
        query.CreateCriteria("Street", 
"street").Add(Subqueries.Exists(streetQuery )); 
    } 
} 

What Am I doing wrong?
Please help

  • 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-16T17:35:06+00:00Added an answer on May 16, 2026 at 5:35 pm

    Just like the error message – you need to set a projection for any subqueries.

    Your variable addressQuery, a DetachedCriteria, is used as a subquery, but it doesn’t have a projection. The relevant portion of the query, when converted to SQL, would look like this:

    ... EXISTS(SELECT FROM Address WHERE HouseNumber = @HouseNumber)
    

    … which is invalid SQL because no columns (a.k.a projections) have been specified in the select clause.

    Use SetProjection to specify the columns.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem: $id is id for each user $img = 'http://www.somesite.com/pictures/'; $no_img
I have this problem when i try to synchronize a observable list with listbox/view
i am having this problem try to use the cocos2d CCScrollLayer I have added
So I have this problem with strings and switch-case, and I'll try to keep
OK, I'm going to try my best to explain my problem. I have this
I have a very strange problem when I try to implement click on table
I have a big problem with a java program. I try to implement a
I have used this guid: http://www.c-sharpcorner.com/uploadfile/shivprasadk/wcf-faq-part-5-transactions/ Why doesnt it rollback?? I dont understand! I
I have this problem: I want to generate a new source code file from
I have this problem since I'm beginning in OOP programming I want to close

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.