Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Sounds like you should be wanting to use:</p> <pre><code>query = query.Where( Entity.StringProperty.Contains("SearchString") ) </code></pre> <p>This should map to:</p> <pre><code>WHERE StringProperty LIKE '%SearchString%' </code></pre> <p>This should also work for more advanced search masks such as "Mr? Sm%th", but I haven't had to test any search strings like that myself yet.</p> <hr> <p><strong>UPDATE: Based on OPs edit</strong></p> <p>It sounds like what you are asking for is something like the following:</p> <pre><code> public enum SelectedComparsionType { StartsWith, EndsWith, Contains } public static bool Like(this string searchString, string searchPattern, SelectedComparsionType searchType) { switch (searchType) { case SelectedComparsionType.StartsWith: return searchString.StartsWith(searchPattern); case SelectedComparsionType.EndsWith: return searchString.EndsWith(searchPattern); case SelectedComparsionType.Contains: default: return searchString.Contains(searchPattern); } } </code></pre> <p>This would allow you to write code as you require, i.e:</p> <pre><code>query = query.Where( Entity.StringProperty.Like("SearchString", SelectedComparsionType.StartsWith) ) </code></pre> <p>However, <strong><em>personally</em></strong>, I would replace any use of SelectedComparsionType, with a direct call to the required string function. I.e</p> <pre><code>query = query.Where( Entity.StringProperty.StartsWith("SearchString") ) </code></pre> <p>As this will still map to a SQL 'LIKE' query.</p>
    singulars
    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.
    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