VB.NET Linq SQL LIKE question... RRS feed

  • Question

  • Hi,

    I have the following SQL query built up dynamically - basically the user enters a search query into a textbox, the code takes the text entered, splits it on the whitespace charector, then adds a SQL LIKE clause for each word - effectively returning results where the column contains all the values they have entered in the search box - irrespective of the order in which they entered them (i.e. "brown dog" would match the same results as "dog brown"):

     For Each word As String In DataHelpers.TokenizeAndCleanseStringForSQLLike(Me.txtSearch.Text.Trim)
                    query += "Product.ProductName LIKE '%" & word & "%' AND "

    My question is - how can I translate this to LINQ to SQL in VB.NET - I know I can use .ToLower.Contains(Me.txtSearch.Text.Trim) - but this will only generate 1 SQL LIKE clause in the resultant SQL query - would anyone be able to tell me how to achieve the same behaviour using LINQ? - I basically need something like .ToLower.Contains(<LIST OF TOKENS TO MATCH>)...

    Many thanks! Smile

    Monday, July 28, 2008 6:47 PM