.net - LINQ to SQL: How to check if any item in one entity collection exists in another entity collection? -
i'm using mvc2 , entity framework.
i have 2 entity collections , need compare them , check if have items in common. example, have entitycollection<candidate> , entitycollection<job>. i'm trying return candidates have skill listed in job's preferred skills. correct:
public iqueryable<candidate> getmatchingcandidates(job job) { return candidate in _db.candidates (candidate.candidateskills.where(c => job.jobpreferredskills.any(j => j.skillid== c.skillid)).count() > 0) select candidate; } similarly, i'd candidates have skills listed in preferred skills.
i'd use any() in first case:
public iqueryable<candidate> getmatchingcandidates(job job) { return candidate in _db.candidates (candidate.candidateskills.any(c => job.jobpreferredskills.any(j => j.skillid == c.skillid))) select candidate; } then use all() second case (all skills have in preferred skills)
public iqueryable<candidate> getmatchingcandidates(job job) { return candidate in _db.candidates (candidate.candidateskills.all(c => job.jobpreferredskills.any(j => j.skillid == c.skillid))) select candidate; }
Comments
Post a Comment