[英]Find records that contains at least one word of a string
我有桌子医生
Doctors:
------------
ID
FullName
用户插入了一个字符串,该字符串可能包含许多单词,例如:“ Leon Simmons”,而我想让所有名字都带有“ Leon”或“ Simmons”的医生使用。 问题是我不知道用户将插入多少个单词。 我如何用linq做这样的事情?
您可以使用SqlMethods.Like()。
用法示例:
var results =
from d in doctors
where SqlMethods.Like(u.FullName, "%Leon Simmons%")
select d;
一种使用linq方法语法的可能解决方案:
dbContext.Doctors
.Where(d => d.FullName.Contains("Leon") || d.FullName.Contains("Simmons"))
.Count();
尝试:
IQueryable<Doctor> doctorQuery = dbContext.Doctors;
foreach(var word in searchWords)
doctorQuery = doctorQuery.Where(x => x.FullName.ToLower().Contains(word.ToLower());
return await doctorQuery.ToListAsync();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.