title: C~ LINQ search functionality on multiple table
body: <p>I am trying to build a search functionality and I am looking for building a Expression tree.</p>
  
  <p>Sorry to be frank I not sure which approach to take..</p>
  
  <p>I have three table to search and based on 3 search field.</p>
  
  <p><strong>Table 1:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/LpxmE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LpxmE.png" alt="enter image description here"></a></p>
  
  <p><strong>Table 2:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/64jGQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/64jGQ.png" alt="enter image description here"></a></p>
  
  <p><strong>Table 3:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/omhfD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/omhfD.png" alt="enter image description here"></a></p>
  
  <p>Search Field I have are:</p>
  
  <ol>
  <li>TCode [Table1]</li>
  <li>Band [Table2]</li>
  <li>RTCode [Table3]</li>
  </ol>
  
  <p><strong>OutPut List:</strong></p>
  
  <p>TCode , Band , T1Id. </p>
  
  <pre><code>Class Response{
  public string TCode {get;set}
  public string RTCode {get;set}
  public int Band {get;set}
  }
  </code></pre>
  
  <p>I tried to get <code>IQuerable&lt;Table1&gt;</code> and started to build search condition like</p>
  
  <pre><code>queryObj = IQuerable&lt;Table1&gt;
   If(TCode not empty)
  {
        queryObj = queryObj.Where(x=&gt;x.TCode== input.TCode));
   }
  If(Band not Empty)
  {
     queryObj = queryObj.Include(x=&gt;x.table2.Where(x=&gt;x.Brand==input.Brand))
  }
  
  if(rTcode Not empty)
  {
    queryObj = queryObj.Include(x=&gt;x.table3.Where(x=&gt;x.RTCode==input.RTCode)
  }
  </code></pre>
  
  <p>Then I want to select TCode , Band , T1Id Column.</p>
  
  <pre><code>var queryObj.SelectMany(x=&gt;x.table2).Select(y=&gt; new Response(){
  T1Id = y.T1Id,
  Band= y.Band,
  TCode = y.Table1.TCode
  }).ToList()
  </code></pre>
  
  <p>I am getting The property expression Not valid error on converting to ToList.</p>
  
  <blockquote>
    <p>The property expression 'x => {from Table2 y in
    [_1].Table2 where ([y].Band == __inputObj_Band_0) select
    [y]}' is not valid.  The expression should represent a property
    access: 't => t.MyProperty'.</p>
  </blockquote>
  
  <p>I am sure the above statement is not correct.</p>
  
  <p>So can anyone advise me how to approach this search functionally, so that it can be extended at any point on different field or adding more table as well.</p>