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

  • Home
  • SEARCH
  • 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 8375625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:13:30+00:00 2026-06-09T15:13:30+00:00

I am having a lot of difficulty figuring out how to perform a query

  • 0

I am having a lot of difficulty figuring out how to perform a query on 2 tables that don’t have reference to each other in code, for example, I have

Customer -> Product* where customer and product have reference to each other

and
Inventory -> Product* where product does not have reference to Inventory

I would like to find all customer who dont have their product in inventory.

I have done this so far

var subQueryInv= DetachedCriteria.For<Inventory>();
        subQueryInv
            .Add(Restrictions.IsNotNull("Product.Id"))
            .SetProjection(Projections.Property<Inventory>(inv=> inv.Product.Id));

        var subQueryProd = DetachedCriteria.For<Product>();
        subQueryTire
            .Add(Subqueries.PropertyNotIn("Id", subQueryInv))
            .SetProjection(Projections.Property<Tire>(prod=> prod.Customer.Id));

        var subQueryCust= DetachedCriteria.For<Customer>();
        subQueryCust
            .Add(Subqueries.PropertyIn("Id", subQueryProd))
            .SetProjection(Projections.Property<TireSet>(cust => cust.Id));

That works, bt the query is very innefficient, it is generating SQL like this for the Inventory part
…WHERE Product.Id NOT IN (SELECT Inventory.ProductId FROM Inventory WHERE Inventory.ProductId IS NOT NULL)

So for each product record, it is querying the entire Inventory table. How can I get the subquery to have a reference to the parent Id like this:

    ...WHERE Product.Id NOT IN (SELECT Inventory.ProductId FROM Inventory WHERE Inventory.ProductId IS NOT NULL AND Inventory.ProductId = Product.Id)

?

  • 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-09T15:13:31+00:00Added an answer on June 9, 2026 at 3:13 pm

    you can use an alias to reference the main criteria

    var subQueryInv= DetachedCriteria.For<Inventory>();
        .Add(Restrictions.IsNotNull("Product.Id"))
        .Add(Restrictions.PropertyEq("Product", "product"))
        .SetProjection(Projections.Property<Inventory>(inv => inv.Product.Id));
    
    var subQueryProd = DetachedCriteria.For<Product>("product");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been having a lot of trouble figuring this out. So I'm using inline
I'm developing an event booking application and am having difficulty figuring out how to
I'm having a lot of difficulty matching an image url with spaces. I need
I'm having a lot of difficulty getting strophe's 'attach()' function working. I am working
It seems this should be easy but I'm having a lot of difficulty using
I'm having a lot of difficulty getting core data to work in my application.
I am reading about encryption and having a lot of difficulty understanding these 3
I'm having a lot of difficulty with CoreData. The learning curve is very steep.
I am having a lot of difficulty using the CSS 3 columns style. I'm
I'm having a lot of difficulty resuming an SSL session on Android using HttpClient.

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.