title: Dynamic Lambda with all properties of a property of an object
body: <p>I had asked a question on how to dynamically compile a LINQ query with all the properties of an object and houlgap had been kind enough to give me the following code</p>
  
  <pre><code>    private static Func&lt;MyEntity, bool&gt; GenerateLambda(MyEntity _myEntity, PropertyInfo propertyInfo)
  {
      var instance = Expression.Parameter(propertyInfo.DeclaringType, "i");
      var property = Expression.Property(instance, propertyInfo);
      var propertyValue = Expression.Constant(propertyInfo.GetValue(_myEntity, null));
      var equalityCheck = Expression.Equal(property, propertyValue);
      return Expression.Lambda&lt;Func&lt;MyEntity, bool&gt;&gt;(equalityCheck, instance).Compile();
  }
  </code></pre>
  
  <p>This works great if the property to be queried is directly a member of the object but for me there is an intermediate property in between. For e.g. The Func Delegate is for another type e.g. Func<code>&lt;ABCMyEntity,bool&gt;</code> while the MyEntity is a member of this object (ABCMyEntity.MyEntity). The Propertyinfo object which is passed is a member of MyEntity.</p>
  
  <p>I know it sounds terribly confusing but I am not able to better explain it. (Maybe because I am not a native speaker). Please ask me if something is not clear in the question. </p>
  
  <p>It is continued from <a href="https://stackoverflow.com/questions/4183092/constructing-dynamic-linq-queries-with-all-properties-of-an-object">Constructing Dynamic LINQ queries with all properties of an object</a></p>