title: Build an lambda Expression tree with a specific field in a linked entity
body: <p>Data MODEL</p>
  
  <pre><code>public class TABLE
      {
          [Key]
          public int ID { get; set; }
          public int ONEFIELD { get; set; }
  
          // -------------------- ForeignKey --------------------
          [ForeignKey("People")]
          public long PeopleID { get; set; }
          public virtual People People { get; set; }
      }
  
      public class People
      {
          [Key]
          public long PeopleID { get; set; }
          public int CountryID { get; set; }
      }
  </code></pre>
  
  <p>I need to build a lambda to query this MODEL :</p>
  
  <blockquote>
    <p>Get TABLE.ONEFIELD = 1 AND TABLE.PEOPLE.COUNTRYID = 6</p>
  </blockquote>
  
  <p>LINQ equivalent</p>
  
  <pre><code>_context.TABLEs
    .Where(e =&gt; e.ONEFIELD == 1)
    .Include(e =&gt; e.People)
    .Where(i=&gt;i.People.CountryID == 6);
  </code></pre>
  
  <p>My try</p>
  
  <pre><code>  public static Expression&lt;Func&lt;TEntity, bool&gt;&gt; BuildLambda&lt;TEntity&gt;(OBJTYPE obj)
          {
  
          var item = Expression.Parameter(typeof(TEntity), "table");
          Expression query = null;
  
  
          // 1
          var prop1 = Expression.Property(item, "ONEFIELD");
          var value1 = Expression.Constant(1);
          var equal1 = Expression.Equal(prop1, value1);
          var lambdaFIELDONE = Expression.Lambda&lt;Func&lt;TEntity, bool&gt;&gt;(equal1, item);
          query = lambdaFIELDONE.Body;
  
          // 2
          var prop2 = Expression.Property(item, typeof(People).Name + ".CountryID");
          var value2 = Expression.Constant(6);
          var equal2 = Expression.Equal(prop2, value2);
          var lambdaCOUNTRYID = Expression.Lambda&lt;Func&lt;TEntity, bool&gt;&gt;(equal2, item);
          query = Expression.And(query, lambdaCOUNTRYID);
  
      }
  </code></pre>
  
  <p>but I receive this error</p>
  
  <blockquote>
    <p>System.ArgumentException: Instance property 'People.CountryID' is not defined for type 'SOLUTION.Models.TABLE'</p>
  </blockquote>
  
  <p>I don't need Generic, just a fixed lambda (and I couldn't use LINQ).</p>
  
  <p>I tried several things to catch People.CountryID like</p>
  
  <pre><code>Expression.Property(item1, typeof(People).GetProperty("CountryID"));
  Expression.Property(item, typeof(People).Name+"." + typeof(People).GetProperty("CountryID"));
  Expression.Property(item, typeof(People).Name + "." + typeof(People).GetProperties().Where(x =&gt; x.Name == "CountryID").FirstOrDefault().Name);
  </code></pre>
  
  <p>no success</p>
  
  <p>Any ideas ? thanks</p>