在List.Contains方法中,如何更改以下linq查询以适应部分搜索,就像我们在sql中使用 LIKE
一样AllDegrees.Listt = new List<string>();
.....
.....
.....
.....
var query = from q in query
join ce in context.CandidateEducations
on q.c.Candidate_OID equals ce.Candidate_OID
where AllDegrees.Listt.Contains(ce.Degree)
select q;
实际情况是我在AllDegrees.Listt中有kaaal,jaaaal,baaal,maaal。现在,如果ce.Degree是ka或al或ja或aa,那么该行应该包含在我的结果集中。
答案 0 :(得分:2)
AllDegrees.Listt.Where(x => x.Contains("your string")).Any();
答案 1 :(得分:2)
检查一下,
private List<string> findDegreesLoop()
{
var list1 = new List<string>();
var list2 = new List<string>();
var list3 = new List<string>();
foreach (var degree in list2)
{
var matches = list1.Where(q => q.Contains(degree)).ToList();
if (matches.Any())
{
list3.AddRange(matches);
}
}
return list3;
}
private List<string> findDegreesLinq()
{
var list1 = new List<string>();
var list2 = new List<string>();
var list3 = new List<string>();
foreach (var matches in list2.Select(degree => list1.Where(q => q.Contains(degree)).ToList()).Where(matches => matches.Any()))
{
list3.AddRange(matches);
}
return list3;
}
答案 2 :(得分:1)
不确定这是否是您正在寻找的。这是一个实现contains(~SQL LIKE)方法的简单示例。
context.CandidateEducations.Where(d=>d.ToLower().Trim().Contains(MyVariable.ToLower().Trim()))