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

The Archive Base Latest Questions

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

Here is my scenario (Tables): Orders ====================== Id (int) description (varchar) Products ====================== Id

  • 0

Here is my scenario (Tables):

Orders
======================
Id (int)  
description (varchar)

Products
======================
Id (int)
description (varchar)

OrderProductXREF (cross reference table)
======================
ProductId (int)
OrderId (int)

I think you get an idea. Nothing unusual is here.

When imported to EDMX file OrderProductXREF table is not visible entity. All I see is navigational properties: Products for entity Order and Orders for entity Product.

So, my problem:
I need Linq and/or Lambda statement that will list all Products that don’t have any Orders associated with. Or, list all Products that are never ordered.

SQL would go like this:

SELECT * FROM Products
WHERE Id NOT IN 
   (SELECT ProductId 
    FROM OrderProductXREF)

EDIT:
Uh… sorry forgot one little detail in my question.

Here is the new SQL:

SELECT * FROM Products
WHERE Id NOT IN 
   (SELECT ProductId 
    FROM OrderProductXREF
    WHERE OrderID = 1)

In words, All Products that are NOT ORDERED in order with ID = 1

Thanks

  • 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-31T17:13:17+00:00Added an answer on May 31, 2026 at 5:13 pm

    Apologies – misread the question beforehand. I suspect you want:

    var query = db.Products.Where(product => !product.Orders.Any());
    

    You should definitely check the generated SQL though. I would expect it to be sensible, but if it’s not, you would probably want to look at other alternatives.

    EDIT: To check products not in order ID 1, you could probably use:

    var query = db.Products.Except(db.Orders
                                     .Where(order => order.Id == 1)
                                     .Single()
                                     .Products);
    

    Or:

    var query = db.Products.Where(product => !product.Orders
                                                     .Where(order => order.Id == 1)
                                                     .Any());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my scenario (tables): Departments ==================== Id (int) Name (varchar) Employees ==================== Id
Here's the scenario: I have 2 tables: CREATE TABLE dbo.API_User ( id int NOT
Here's the scenario: I have 2 tables with data, one is the 2009 version
Here is a simple scenario with table characters: CharacterName GameTime Gold Live Foo 10
Here's my scenario: I've got a table of (let's call them) nodes. Primary key
Here is the scenario: SQL Server 2000 (8.0.2055) Table currently has 478 million rows
Here's the scenario -- I have two tables Names & Sentences: Names Sentences ID
Here is my scenario: I have two tables: subfirms and subfirmdetails. I am trying
Ok, let me explain the scenario. I have a orders table with a auto
Here is the scenario: I have a brand new database, with the tables with

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.