title: Simple Where Clause in Expression Tree
body: <p>I am attempting to build a simple Where clause.</p>
  
  <p><strike>This is the code that does not work:</strike></p>
  
  <p><strong>EDIT</strong> this code works fine now (thanks to answers below).</p>
  
  <pre><code>public class Item
  {
      public int Value { get; set; }
      public string Name { get; set; }
  }
  
  var _List = new List&lt;Item&gt;
  {
      new Item{ Name = "Smith", Value = 1},
      new Item{ Name = "Smith", Value = 2},
      new Item{ Name = "Wesson", Value = 3},
      new Item{ Name = "Wesson", Value = 4},
  };
  
  // Where(x =&gt; x.Value == 1)
  var _Type = typeof(Item);
  var _Prop = _Type.GetProperty("Value");
  var _Param = Expression.Parameter(_Type, _Prop.Name);
  var _Left = Expression.PropertyOrField(_Param, _Prop.Name);
  var _Right = Expression.Constant(1, _Prop.PropertyType); 
  var _Body = Expression.Equal(_Left, _Right);
  var _Where = Expression.Lambda&lt;Func&lt;Item, bool&gt;&gt;(_Body, _Param); 
  var _Result = _List.AsQueryable().Where(_Where);
  </code></pre>
  
  <p>Thank you.</p>