score:3

Accepted answer

I'd use Any() in the first case:

    public IQueryable<Candidate> GetMatchingCandidates(Job job)
    {
        return from candidate in _db.Candidates
               where (candidate.CandidateSkills.Any(c => job.JobPreferredSkills.Any(j => j.SkillId == c.SkillId)))
               select candidate;
    }

Then use All() for your second case (all skills have to be in the preferred skills)

    public IQueryable<Candidate> GetMatchingCandidates(Job job)
    {
        return from candidate in _db.Candidates
               where (candidate.CandidateSkills.All(c => job.JobPreferredSkills.Any(j => j.SkillId == c.SkillId)))
               select candidate;
    }

Related Articles