EF linq/lambda .contains(list [String])? [英] EF linq/lambda .contains(list[String])?
本文介绍了EF linq/lambda .contains(list [String])?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有任何方法可以评估字符串是包含列表中的某些元素还是列表中的所有元素?使用linq来实体吗?
is there any way to evaluate if a string contains some of the elements of a list or all the elements of the list? using linq to entities?
我一直在尝试使用predicateBuilder和其他工具,但不是在其中使用%100.
i have been trying to use predicateBuilder and others but im not %100 into thoses.
编辑
类似:
string[] words = searchString.Split(' ');
var resultado = db.users
.Where(u => u.fullName.contains(words) )
.Select(s => new { user_id = s.id_user, nombre = s.fullName})
.ToList();
推荐答案
您需要反转对Contains
的使用,以检查words
集合中的fullName
:
You need to reverse your use of Contains
to check the words
collection for the fullName
:
string[] words = searchString.Split(' ');
var resultado = db.users
.Where(u => words.Contains(u.fullName))
.Select(s => new { user_id = s.id_user, nombre = s.fullName})
.ToList();
与words
数组中的一个项目匹配.
That will match one item in the words
array.
要匹配用户fullName
中words
的全部,请使用All
:
To match all of words
in a user's fullName
, use All
:
var resultado = db.users
.Where(u => words.All(w => u.fullName.Contains(w))
.Select(s => new { user_id = s.id_user, nombre = s.fullName})
.ToList();
这篇关于EF linq/lambda .contains(list [String])?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文