The Problem
Using Link to SQL I would like to filter by columns that I do not want returned in the select statement. This works fine as long as the query is built all at once. In situations where I try and build the where clause dynamically, I get a compile time error because the column is not included in the select.
Example
WORKS
Dim resultA = From logItem In dc.Log
Where logItem.Message.Contains(searchText)
Select logItem.LogID, logItem.DateLogged
DOES NOT WORK
Dim resultB = From logItem In dc.Log
Select logItem.LogID, logItem.DateLogged
If (Not String.IsNullOrEmpty(searchText)) Then
resultB = q.Where(Function(logItem)
logItem.Message.Contains(searchText))
End If
I am not sure not how to get round this. Any help appreciated!