I’m using MVC2 and Entity Framework.
I have 2 Entity Collections and I need to compare them and check if they have any items in common. For example, say I have EntityCollection<Candidate> and EntityCollection<Job>. I’m trying to return all candidates that have a skill that is listed in the job’s preferred skills. Is this correct:
public IQueryable<Candidate> GetMatchingCandidates(Job job)
{
return from candidate in _db.Candidates
where (candidate.CandidateSkills.Where(c => job.JobPreferredSkills.Any(j => j.SkillId== c.SkillId)).Count() > 0)
select candidate;
}
Similarly, I’d also like to get candidates that have ALL skills that are listed in the preferred skills.
I’d use
Any()in the first case:Then use
All()for your second case (all skills have to be in the preferred skills)