Skip to content

Instantly share code, notes, and snippets.

@cincauhangus
Created July 27, 2017 06:43
Show Gist options
  • Select an option

  • Save cincauhangus/3a976c1d937271b6392d398364b4dcde to your computer and use it in GitHub Desktop.

Select an option

Save cincauhangus/3a976c1d937271b6392d398364b4dcde to your computer and use it in GitHub Desktop.
SQL to LINQ String Comparison
Dim value = "F!NDM3"
' strColumn LIKE '%F!NDM3%'
Dim results1 = (From row In table Where row.strColumn.Contains(value) Select row.id)
' strColumn LIKE 'F!NDM3%'
Dim results2 = (From row In table Where row.strColumn.StartsWith(value) Select row.id)
' strColumn LIKE '%F!NDM3'
Dim results3 = (From row In table Where row.strColumn.EndsWith(value) Select row.id)
' strColumn LIKE 'F!NDM3'
Dim results4 = (From row In table Where System.Data.Linq.SqlClient.SqlMethods.Like(row.strColumn, value) Select row.id)
' strColumn = 'F!NDM3'
Dim results5 = (From row In table Where String.equals(row.strColumn, value) Select row.id)
' strColumn = 'F!NDM3'
Dim results6 = (From row In table Where row.strColumn.equals(value) Select row.id)
' strColumn = 'F!NDM3' (case insensitive)
Dim results7 = (From row In table Where String.compare(row.strColumn, value, StringComparison.OrdinalIgnoreCase) = 0 Select row.id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment