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

Related Questions

I have this SQL Query that pulls data from 3 tables. I am unable
I have a data.table object like this one library(data.table) a <- structure(list(PERMNO = c(10006L,
I'm a bit confused on this. I have a data table structured like this:
I have a data.table object similar to this one library(data.table) c <- data.table(CO =
I have a table like this: Application,Program,UsedObject It can have data like this: A,P1,ZZ
My table have data structure like this cate_id task_id date_start date_end other 34 14
Say I have this table schema. ID AccNo Amount Say I have this data
I have this data in a table, for instance, id name parent parent_id 1
I have a table like this... CustomerID DBColumnName Data 1 FirstName Joe 1 MiddleName
I have no control over how the data is saved in this table. However,

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.