问题描述:

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.

相关阅读:
Top