title: Generate query expression from a string
body: <p>I am trying to map a front end query builder to a backend ORM (OrmLite).</p>
  <p>For instance, the front end might send 3 string values: <code>SomeField</code>, <code>=</code> <code>foo</code>.</p>
  <p>If I want to generate this query in the ORM I would do:</p>
  <pre><code>var q = db.From&lt;MyEntity&gt;()
            .Where(x =&gt; x.SomeField == &quot;foo&quot;)
            
  </code></pre>
  <p>So what I need to do is come up with a way to build the where predicate from a string.</p>
  <p>I can see the type <code>Where</code> is expecting is: <code>Expression&lt;Func&lt;MyEntity,bool&gt;&gt;</code></p>
  <p>So I think I need something like:</p>
  <pre class="lang-cs prettyprint-override"><code>
  var q = db.From&lt;MyEntity&gt;()
            .Where(GetQueryPart(&quot;SomeField&quot;, &quot;=&quot;, &quot;foo&quot;);
            
  //....
  
  public Expression&lt;Func&lt;T,bool&gt;&gt; GetQueryPart&lt;T&gt;(string field, string queryOperator, string value)
  {
      //...
      
  }
  </code></pre>
  <p>But I am not exactly sure if this is the right approach or where exactly to start.  I had a look through the docs here <a href="https://docs.microsoft.com/en-us/dotnet/api/system.linq.expressions.expression?view=net-5.0" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/dotnet/api/system.linq.expressions.expression?view=net-5.0</a> and it is not clear to me how to build an expression.</p>
  <p>Can someone give me some help with how I should approach this?</p>