当前位置: 动力学知识库 > 问答 > 编程问答 >

asp.net mvc - Filtering with unrelated entities using EF

问题描述:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: