title: How to do Entity Framework/Linq join in query with where clause expressions
body: <p>I have a Entity Framework query where the where clauses' change based on several selections.<br />
  Here is my code:</p>
  <pre><code>Expression&lt;Func&lt;CtCsGroup, bool&gt;&gt; where_expression1 = x =&gt; 1 == 1;
  Expression&lt;Func&lt;CtCsGroup, bool&gt;&gt; where_expression2 = x =&gt; 1 == 1;
  Expression&lt;Func&lt;CtCsGroup, bool&gt;&gt; where_expression3 = x =&gt; 1 == 1;
  
  
  if (selections.SearchCSGroup.NoNull() != &quot;&quot;)
  {
      where_expression1 = x =&gt; x.CsGroup.ToUpper() == selections.SearchCSGroup.ToUpper();
  }
  
  if (selections.SearchUserId.NoNull() != &quot;&quot;)
  {
      where_expression3 = x =&gt; x.UsrIdn.ToUpper() == selections.SearchUserId.ToUpper();
  }
  
  if (!selections.SearchIncludeRetires)
  {
      where_expression2 = x =&gt; x.CsRetire != &quot;Y&quot;;
  }
  
  var groupDTOs = (from g in _infobaseContext.CtCsGroup
                   .Where(where_expression1)
                   .Where(where_expression2)
                   .Where(where_expression3)
                   select new
                   {
                       UsrIdn = g.UsrIdn,
                       CsGroup = g.CsGroup,
                       CsRetire = g.CsRetire,
                       CsGroupName = &quot;test&quot; // n.CsGroupName
                   }).ToList();
  </code></pre>
  <p>I want to add a join to another table.</p>
  <p>How do I add this to the above query?  I have tried several different formats but whenever I add it, I get an error <em>&quot;(where_expression1)&quot;</em> ,<em>&quot;(where_expression3)&quot;</em>, etc.</p>
  <p>Thanks.</p>
  <p>Here are some more details...</p>
  <pre><code>var groupDTOs = (from g in _infobaseContext.CtCsGroup
                           join n in _infobaseContext.TblCsGroupList
                                      on g.CsGroup equals n.CsGroup
                           select new
                           {
                               UsrIdn = g.UsrIdn,
                               CsGroup = g.CsGroup,
                               CsRetire = g.CsRetire,
                               CsGroupName =  n.CsGroupName
                           }).ToList();
  
  </code></pre>
  <ul>
  <li>and this one works without the join -</li>
  </ul>
  <pre><code>var groupDTOs = (from g in _infobaseContext.CtCsGroup
                           .Where(where_expression1)
                           select new
                           {
                               UsrIdn = g.UsrIdn,
                               CsGroup = g.CsGroup,
                               CsRetire = g.CsRetire,
                               CsGroupName =  &quot;test&quot;  //n.CsGroupName
                           }).ToList();
  
  </code></pre>
  <ul>
  <li>but when I add both the join and the expression -</li>
  </ul>
  <pre><code>var groupDTOs = (from g in _infobaseContext.CtCsGroup
                           join n in _infobaseContext.TblCsGroupList
                                      on g.CsGroup equals n.CsGroup
                           .Where(where_expression1)
                           select new
                           {
                               UsrIdn = g.UsrIdn,
                               CsGroup = g.CsGroup,
                               CsRetire = g.CsRetire,
                               CsGroupName =  n.CsGroupName
                           }).ToList();
  
  </code></pre>
  <ul>
  <li>Visual Studio is giving this error:
  Argument 2: cannont convert from 'System.Linq.Expressions&lt;System.Func&lt;IBDataServices.Models.CtCsGroup, bool&gt;&gt;' to 'System.Func&lt;char,bool&gt;'
  <img src="https://i.stack.imgur.com/t8luo.png" alt="Error Image:" /></li>
  </ul>