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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:51:32+00:00 2026-05-19T11:51:32+00:00

In the LINQ query below, I want to return the ContractorId found in the

  • 0

In the LINQ query below, I want to return the ContractorId found in the Contractors table. Not all people in the Contacts table are in the Contractors table. What I really want is a list of ContractorIds for those contractors meeting the criteria. ContractorId is not the same as ContactId.

var contractorsWithCertsFor2010 = dc.Contacts.Where(x => x.Contractors
.Any(d => d.ContractorStatus
.Any(date => date.StatusDate.Year >= 2010)))
.Select(x => x.Contractors
.Select(dr => dr.ContractorId)); 

IEnumerable<int> differenceQuery = allPeople.Except(contractorsWithCertsFor2010);

allPeople is a IQueryable<Int> but contractorsWithCertsFor2010 is a IQueryable<IEnumerable<Int>>. Something isn’t right there. The multiple .Select() is causing the IQueryable<IEnumerable<Int>> so I’m looking for a way to eliminate one of the .Select() and get a return of

IQueryable<Int>

Any Suggestions? Thanks!

Solution:
One solution is posted in a reply below. I created another solution prior to seeing that one. In my solution, I started out in the Contractors table instead of the Contacts table, eliminating one layer and one .Select() statement.

  • 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-19T11:51:33+00:00Added an answer on May 19, 2026 at 11:51 am

    Assuming you only want contractors that have contact record and since the only thing you selecting is the contractor id, you might want to try this:

    var contractorsWithCertsFor2010 = dc.Contractors
        .Where(c => c.Contacts.Any() && c.ContractorStatus
            .Any(cs => cs.StatusDate.Year >= 2010))
        .Select(c => c.ContractorId);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below linq query does not work, because the subquery line. if comment the subquery
I am trying to get the below linq query to return -1 if there
My LINQ query is not producing the expected output below. Basically, it's the sum
I've written a LINQ query that should return an int value. but I'm not
I want to Enumerate Linq Query. Below i specified example. EX: DataTable _slidingDataTable =
I have LINQ Query which return result in below format -- Parent1 ----Childs ------key
I have the below LINQ query. FactColumns is a list of FactColumn objects and
I've written a LINQ query shown below : List<Actions> actions = resourceActions.Actions.Select(s => s.ActionName).ToList();
I want to run a linq query that will return values to my custom
My current LINQ query and example XML are below. What I'd like to do

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.