0

How do I pass a list of strings to contain?

var test= _context.TableName.Where(e => e.type == "icon" && e.Code.Contains("list of string"));

Regards

monika-115
  • 25
  • 3
  • it should be `IEnumerable.Contains(string)` ... it should work with LINQ but of course it may not work with EF – Selvin Nov 03 '21 at 12:52
  • What about turning things around and doing `"list of strings".Contains(e.Code)`? – devsmn Nov 03 '21 at 12:52

2 Answers2

2

Without knowing the details it is somewhat difficult to suggest something but you could just do it in the opposite way:

var test = _context.TableName.Where(e => e.type == "icon" && listOfString.Any(e.Code.Contains));
Fabjan
  • 13,506
  • 4
  • 25
  • 52
0

This should be enough

var setOfStrings = new HashSet(){"string1", "string2"};
var test = _context.TableName.Where(e => e.type == "icon" && setOfStrings.Contains(e.Code));
milo
  • 445
  • 5
  • 12