title: How to make an List of Objects a parameter in a Lamba using C# Expression API
body: <p>I'm trying to dynamically create an predicate to pass into a linq where clause. This is for a generic method that takes two list of the same Type and and list of property names to compare.</p>
  
  <pre class="lang-cs prettyprint-override"><code>void SomeMethod&lt;T&gt;(List&lt;T&gt; oldRecords, List&lt;T&gt; newRecords, List&lt;string&gt; propertiesOfT)
  {
      // dynamically build predicate for this
      var notMatch = oldRecords.Where(o =&gt; !newRecords.Any(n =&gt; n.Prop1 == o.Prop1 &amp;&amp; n.Prop2 == o.Prop2)).ToList();
  
      // do somethind with notMatch
  
  }
  </code></pre>
  
  <p>I would like to convert this: </p>
  
  <pre class="lang-cs prettyprint-override"><code>var notMatch = oldRecords.Where(o =&gt; !newRecords.Any(n =&gt; n.Prop1 == o.Prop1 &amp;&amp; n.Prop2 == o.Prop2)).ToList();
  </code></pre>
  
  <p>To achieve this:</p>
  
  <pre class="lang-cs prettyprint-override"><code>var predicate = "n =&gt; n.Prop1 == o.Prop1 &amp;&amp; n.Prop2 == o.Prop2"; // sudo code
  var notMatch = oldRecords.Where(o =&gt; !newRecords.Any(predicate));
  </code></pre>
  
  <p>or this</p>
  
  <pre class="lang-cs prettyprint-override"><code>var predicate = "o =&gt; !newRecords.Any(n =&gt; n.Prop1 == o.Prop1 &amp;&amp; n.Prop2 == o.Prop2)" // sudo code
  var notMatch = oldRecords.Where(predicate);
  </code></pre>
  
  <p>How do I populate newRecords when dynamically creating the Expression?
  And how would I reference parameter o and parameter n in the Expresssion.</p>
  
  <p>I've gotten this far:</p>
  
  <pre class="lang-cs prettyprint-override"><code>//construct the two parameters
  var o = Expression.Parameter(typeof(T), "o");
  var n = Expression.Parameter(typeof(T), "n");
  
  // How to I go about populating o with values and n with values
  // from oldRecords and newRecords? or is that no neccessary
  
  var property = Expression.Property(o, typeof(T).GetProperty("Id").Name);
  
  var value = Expression.Constant(Convert.ChangeType("12345", typeof(T).GetProperty("Id").PropertyType), typeof(T).GetProperty("Id").PropertyType);
  
  BinaryExpression binaryExpression = Expression.MakeBinary(ExpressionType.Equal, property, value);
  </code></pre>
  
  <p>Any sudo code or clue where to look to achieve this?</p>