【发布时间】:2019-03-14 14:53:13
【问题描述】:
有 Candidate 和 Job 实体:
public class Candidate
{
public int CandidateId { get; set; }
public string Name { get; set; }
public string SkillTags { get; set; }
public List<string> skillTagsList
{
get
{
return Array.ConvertAll(SkillTags.Split(','), p => p.Trim()).ToList();
}
}
}
public class Job
{
public int JobId { get; set; }
public string Name { get; set; }
public string Company { get; set; }
public string Skills { get; set; }
public List<string> skillsList
{
get
{
return Array.ConvertAll(Skills.Split(','), p => p.Trim()).ToList();
}
}
}
对于每项工作,我都希望获得最匹配技能的候选人。 此 LINQ 查询返回错误。是否有更好的 LINQ 查询来获取结果?
List<Candidate> candidates = repository.GetCandidates().Result;
List<Job> jobs = repository.GetJobs().Result;
List<Candidate> JobCandidates = null;
jobs.ForEach(j =>
{
JobCandidates = candidates.Where(c => c.skillTagsList.Any(st => j.skillsList.Contains(st.ToLower())));
}
【问题讨论】:
-
使用
Join代替where和any方法。 -
@Sham 在这种情况下有什么帮助?
-
仅供参考,您的列表属性可以通过以下方式变得更简单:
public List<string> skillsList => Skills.Split(',').Select(s => s.Trim()).ToList();