EF linq / lambda.contains (list [String])?

Is there a way to evaluate if a string contains any list items or all list items? using linq for entities?

I am trying to use predicateBuilder and others, but im not% 100 in thoses.

EDIT

sort of:

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(); 
+4
source share
2 answers

You need to cancel the use of Contains to check the words collection for 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(); 

This will match element one in the words array.

To match all words to the fullName user, 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(); 
+13
source

This is best done with intersect

  IEnumerable<string> first = ...; IEnumerable<string> second= ...; var duplicates = first.Intersect(second); 

and doest contains

 bool contains = duplicates.Any(); 
0
source

Source: https://habr.com/ru/post/1483374/


All Articles