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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:34:17+00:00 2026-05-10T17:34:17+00:00

I have a data tables with this type of setup. Table A AID AName

  • 0

I have a data tables with this type of setup.

Table A

AID     AName --------------------- 1       A_Name1 2       A_Name2 3       A_Name3 

Table B

BID     BName --------------------- 10      B_Name1 20      B_Name2 30      B_Name3 

Table C

AID     BID --------------------- 1       10 2       10 2       20 2       30 3       20 3       30 

I want to use LINQ to write a query that for a given ID of A give me the list of B that is not in table C.

So for AID of 1 I want BID of 20 & 30.

For AID of 3 I want BID of 10

For AID of 2 nothing returned anything returned.

I know the SQL would be

SELECT     B.BID FROM B LEFT OUTER JOIN C ON C.BID = B.BID AND A.AID = 1  -- AID would change based on which I was looking for, 1, 2, or 3 

What is the LINQ Equivalent?

Please assume I have objects that match the tables of A, B, and C accordingly.

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

    For LinqToSql, database optimizer will handle this appropriately. Use the ‘Not Any’ pattern.

    IQueryable<B> query =   db.BTable     .Where(b => !db.CTable       .Where(c=> c.AID == 1)       .Any(c => c.BID == b.BID)     ) 

    For LinqToObjects, we don’t want to enumerate the CList for each item in BList. Do that enumeration one time.

    List<int> BIDList = CList   .Where(c => c.AID == 1)   .Select(c => c.BID)   .ToList(); IEnumerable<B> query = BList   .Where(b => !BIDList.Contains(b.BID)); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 51k
  • Answers 51k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I guess the question I would ask is 'how would… May 11, 2026 at 6:32 am
  • added an answer I think you can achieve pretty much the same effect… May 11, 2026 at 6:32 am
  • added an answer it's not bad, it's just the only way to do… May 11, 2026 at 6:32 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

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.