title: How do I tell linq2db how to translate a given expression, ie Split(char) into SQL when it does not know how to do so?
body: <p>I am using <a href="https://www.nuget.org/packages/linq2db/" rel="nofollow"><code>linq2db</code></a> and while it works well enough for most CRUD operations I have encountered many expressions that it just cannot translate into SQL.</p>
  
  <p>It has gotten to the point where unless I know in advance exactly what kinds of expressions will be involved and have successfully invoked them before, I am worried that any benefit derived from <code>linq2db</code> will be outweighed by the cost of trying to find and then remove (or move away from the server side) the offending expressions.</p>
  
  <p>If I knew how to tell <code>linq2db</code> how to parse an <code>Expression&lt;Func&lt;T,out T&gt;&gt;</code> or whatnot into SQL whenever on an ad-hoc, as-it-is-needed basis, then I would be much more confident and I could do many things using this tool.</p>
  
  <p>Take, for instance, <code>String.Split(char separator)</code>, the method that takes a <code>string</code> and a <code>char</code> to return a <code>string[]</code> of each substring between the separator.</p>
  
  <p>Suppose my table <code>Equipment</code> has a nullable <code>varchar</code> field <code>Usages</code> that contains lists of different equipment usages separated by commas.</p>
  
  <p>I need to implement <code>IList&lt;string&gt; GetUsages(string tenantCode, string needle = null)</code> that will give provide a list of usages for a given tenant code and optional search string.</p>
  
  <p>My query would then be something like:</p>
  
  <pre><code>var listOfListOfStringUsages =
      from et in MyConnection.GetTable&lt;EquipmentTenant&gt;()
      join e in MyConnection.GetTable&lt;Equipment&gt;() on et.EquipmentId = e.EquipmentId
      where (et.TenantCode == tenantCode)
      where (e.Usages != null)
      select e.Usages.Split(','); // cannot convert to sql here
  
  var flattenedListOfStringUsages = 
      listOfListOfStringUsages.SelectMany(strsToAdd =&gt; strsToAdd)
                              .Select(str =&gt; str.Trim())
                              .Distinct();
  
  var list = flattenedListOfStringUsages.ToList();
  </code></pre>
  
  <p>However, it  would actually bomb out at runtime on the line indicated by comment.</p>
  
  <p>I totally get that <code>linq2db</code>'s creators cannot possibly be expected to ship with every combination of <code>string</code> method and major database package.</p>
  
  <p>At the same time I feel as though could totally tell it how to handle this if I could just see an example of doing just that (someone implementing a custom expression).</p>
  
  <p>So my question is: <strong>how</strong> do I instruct <code>linq2db</code> on how to parse an <code>Expression</code> that it cannot parse out of the box?</p>