title: Linq Query with a Where clause in an Include statement
body: <p>I am trying to replace my big, ugly query; although ugly it works as desired:-</p>
  
  <pre><code>using (var ctx = new Data.Model.xxxTrackingEntities())
  {
      var result = ctx.Offenders
          .Join(ctx.Fees, o =&gt; o.OffenderId, f =&gt; f.OffenderId,
          (o, f) =&gt; new { Offenders = o, Fees = f })
          .Join(ctx.ViolationOffenders, o =&gt; o.Fees.ViolationId, vo =&gt; vo.ViolationId,
          (o, vo) =&gt; new { Offenders = o, ViolationOffenders = vo })
          .Join(ctx.Violations, v =&gt; v.ViolationOffenders.ViolationId, vo =&gt; vo.ViolationId,
          (v, vo) =&gt; new { Violations = v, ViolationOffenders = vo })
          .Where(o =&gt; o.Violations.Offenders.Offenders.YouthNumber != "")
          .ToList();
  
      gvwData.DataSource = result;
  }
  </code></pre>
  
  <p>with the following linq Query:-</p>
  
  <pre><code> var result = ctx.Offenders
          .Include(o =&gt; o.Fees.Where(f =&gt; f.Amount != null))
          .Include(o =&gt; o.ViolationOffenders)
          .Include(o =&gt; o.ViolationOffenders.Select(of =&gt; of.Violation))
          .Where(o =&gt; o.YouthNumber != "" &amp;&amp; o.FirstName != "")
          .ToList();
  </code></pre>
  
  <p>I am blowing up on the 2nd line of the query... once I add the Where clause... <code>o =&gt; o.Fees.Where(f=&gt; f.Amount != null)</code></p>
  
  <p>The error message I get...</p>
  
  <blockquote>
    <p>The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties.</p>
  </blockquote>
  
  <p>In addition, I tried writing my query as:-</p>
  
  <pre><code>   var result = ctx.Offenders
          .Include(o =&gt; o.Fees)
          .Include(o =&gt; o.ViolationOffenders)
          .Include(o =&gt; o.ViolationOffenders.Select(of =&gt; of.Violation))
          .Where(o =&gt; o.YouthNumber != "" &amp;&amp; o.FirstName != "" &amp;&amp; o.Fees.Where(f=&gt; f.Amount != null))
          .ToList();
  </code></pre>
  
  <p>But then I get the following error:-</p>
  
  <blockquote>
    <p>Operator '&amp;&amp;' cannot be applied to operands of type 'bool' and 'System.Collections.Generic.IEnumerable</p>
  </blockquote>
  
  <p>I know the concept is right, but I need help with the syntax.</p>