0

The best I can show you what I am trying to achieve is with an example.

Lets say that the user enters a search sentence like 'Microsoft Exchange Server'. So my SQL query would be the following:

SELECT * FROM tbl_Skills
WHERE Line5 LIKE '%Microsoft%' AND Line5 LIKE '%Exchange%' AND Line5 LIKE '%Server%';

So it looks the following in Linq:

.Where(x => x.Line5.Contains("Microsoft") && x.Line5.Contains("Exchange")&& x.Line5.Contains("Server")).ToList();

The problem is that I don't know how many words the user enters into the query. So how would I perform that query with x amount of words. The query has to be an AND search.

Tom el Safadi
  • 6,164
  • 5
  • 49
  • 102

1 Answers1

2

In Where you may use All against a dynamic user word list:

var userWords = new[] { "Microsoft", "Exchange", "Server" };
var selected = tbl_Skills.Where(x => userWords.All(w => x.Line5.Contains(w)));
Dmitry Egorov
  • 9,542
  • 3
  • 22
  • 40