How to simplify LINQ query with multiple .Select () to return IQueryable (int)

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 that meet 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 IQueryable<Int>, but contractors WithithCertsFor2010 is IQueryable<IEnumerable<Int>>.Something is wrong there. Multiple .Select () calls IQueryable<IEnumerable<Int>>, so I'm looking for a way to eliminate one of .Select () and get a return

IQueryable<Int>

Any suggestions? Thank!

: . , . "" "", .Select().

+3
2

, , , , , , :

var contractorsWithCertsFor2010 = dc.Contractors
    .Where(c => c.Contacts.Any() && c.ContractorStatus
        .Any(cs => cs.StatusDate.Year >= 2010))
    .Select(c => c.ContractorId);
+4

: SelectMany, . , , :

//...
.SelectMany(x => x.Contractors
                  .Select(dr => dr.ContractorId)); 

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

Source: https://habr.com/ru/post/1786727/


All Articles