title: Convert List.Contains to Expression Tree
body: <p>Related To: </p>
  
  <p><a href="https://stackoverflow.com/questions/46032599/create-a-lambda-expression-with-3-conditions">Create a Lambda Expression With 3 conditions</a></p>
  
  <p><a href="https://stackoverflow.com/questions/46388971/convert-contains-to-expression-tree">Convert Contains To Expression Tree</a></p>
  
  <p>In the following of my previous question I faced with this query that I want to write <code>Expression Tree</code> version:</p>
  
  <pre><code>List&lt;byte?&gt; lst = new List&lt;byte?&gt;{1,2};
  from a in myTbl
  where a.Age = 20 &amp;&amp; lst.Contains(a.Status)
  select a
  </code></pre>
  
  <p>I write this code:</p>
  
  <pre><code>List&lt;byte?&gt; lst = new List&lt;byte?&gt;{1,2};
  var param = Expression.Parameter(typeof(T), "o");
  var body = Expression.AndAlso(
                 Expression.Equal(
                      Expression.PropertyOrField(param, "Age"),
                      Expression.Constant(20)
                 ),
                 Expression.Call(Expression.PropertyOrField(param, "Status"),
                                     "Contains",
                                     Type.EmptyTypes, 
                                     Expression.Constant(lst)));
  
  var lambda = Expression.Lambda&lt;Func&lt;T, bool&gt;&gt;(body, param);
  return lambda;
  </code></pre>
  
  <p>and I get the error: </p>
  
  <blockquote>
    <p>"No method 'Contains' exists on type 'System.Nullable`1[System.Byte]'."</p>
  </blockquote>
  
  <p>Please help me to find the problem.</p>
  
  <p>Thanks</p>