Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In LINQ to SQL you can add WHERE clauses to your query using the .Where method of the query object, as you noted in your question. To use the LIKE operator, try using the .Contains method of the object you're querying in the Lambda expression of your call to the Where method.</p> <p>Here's a simplified example in a console application. Hopefully it will lead you in the correct direction.</p> <pre><code>Public Class Doc Private _docName As String Public Property DocName() As String Get Return _docName End Get Set(ByVal value As String) _docName = value End Set End Property Public Sub New(ByVal newDocName As String) _docName = newDocName End Sub End Class Sub Main() Dim Documents As New List(Of Doc) Documents.Add(New Doc("ABC")) Documents.Add(New Doc("DEF")) Documents.Add(New Doc("GHI")) Documents.Add(New Doc("ABC DEF")) Documents.Add(New Doc("DEF GHI")) Documents.Add(New Doc("GHI LMN")) Dim qry = From docs In Documents qry = qry.Where(Function(d) d.DocName.Contains("GHI")) Dim qryResults As List(Of Doc) = qry.ToList() For Each d As Doc In qryResults Console.WriteLine(d.DocName) Next End Sub </code></pre> <p>Note the .Contains("GHI") call in the Lambda expression of the .Where method. I'm referencing the parameter of the expression, "d", which exposes the DocName property, which further exposes the .Contains method. This should produce the LIKE query you're expecting.</p> <p>This method is additive, i.e. the call to the .Where method could be enclosed in a loop to make additional LIKE operators added to the WHERE clause of your query.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload