How can we do this in EF,
Member member = db.Members.Find(id);
vmJob.MatchJob = db.Jobs.Where(p=>p.Skills in (member.Skills));
Its just like a job matching function.. wherein the member has a skills, and a job requires skills.
Thanks in advance.
djcohen66 was close. When both are collections, you can use
.Any on the candidate collection.
var member = db.Members.Find(id); var memberSkillIds = member.Skills.Select(ms => ms.SkillId).ToList(); var jobs = db.Jobs.Where(j => j.Skills.Any(js => memberSkillIds.Contains(js.SkillId)));
Try something like this:
Member member = db.Members.Find(id); var memberSkills = member.Skills.Select(ms=>ms.SkillId).ToArray(); //assumes a skill has a skill id. var matchJobs = db.Jobs.Where(mj=> memberSkills.Contains(mj.Skill));
That should return jobs where the job.Skills includes the member's skills.