The "Where" clause requires a boolean value. You can supply that with a function. Here is an example based on my understanding of your issue. You can feed that function whatever arguments you need to generate your "dynamic Where" clause.
Private Sub Test()
Dim items As New List(Of Item)
items.Add(New Item("this is a test"))
items.Add(New Item("this is not a test"))
items.Add(New Item("this is maybe a test"))
items.Add(New Item("something else"))
items.Add(New Item("something else test"))
Dim lookfor As String = "this is a test"
Console.WriteLine("Exact Match: " & lookfor)
For Each itm As Item In GetMatchedItems(items, lookfor, MatchType.Exact)
Console.WriteLine(itm.Title)
Next itm
Console.WriteLine("----------------------")
Console.WriteLine("Contains all: " & lookfor)
For Each itm As Item In GetMatchedItems(items, lookfor, MatchType.ContainsAll)
Console.WriteLine(itm.Title)
Next itm
Console.WriteLine("----------------------")
lookfor = "else not"
Console.WriteLine("Contains one or more: " & lookfor)
For Each itm As Item In GetMatchedItems(items, lookfor, MatchType.ContainsOneOrMore)
Console.WriteLine(itm.Title)
Next itm
End Sub
Private Function GetMatchedItems(ByVal source As List(Of Item), ByVal lookfor As String, ByVal mt As MatchType) As IEnumerable(Of Item)
Return From el In source _
Let itm As Item = DirectCast(el, Item) _
Where MatchTester(itm.Title, lookfor, mt) _
Select itm
End Function
Private Function MatchTester(ByVal teststring As String, ByVal lookfor As String, ByVal match As MatchType) As Boolean
If Not [Enum].IsDefined(GetType(MatchType), match) Then
Throw New ArgumentException("Invalid MatchType")
End If
Select Case match
Case MatchType.Exact
MatchTester = String.Equals(teststring, lookfor)
Case MatchType.ContainsAll, MatchType.ContainsOneOrMore
Dim source As New List(Of String)(teststring.Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries))
Dim findthese As New List(Of String)(lookfor.Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries))
If match = MatchType.ContainsAll Then
MatchTester = True
For Each word As String In findthese
If Not source.Contains(word) Then
MatchTester = False
Exit For
End If
Next word
Else
MatchTester = False
For Each word As String In findthese
If source.Contains(word) Then
MatchTester = True
Exit For
End If
Next
End If
End Select
End Function
Private Enum MatchType
Exact
ContainsAll
ContainsOneOrMore
End Enum 'MatchType
Private Class Item
Public Sub New(ByVal Title As String)
Me._Title = Title
End Sub
Private _Title As String
Public Property Title() As String
Get
Return _Title
End Get
Set(ByVal value As String)
_Title = value
End Set
End Property 'Title
End Class ' Item