title: Getting the right results from a LINQ statement
body: <p>I am using a LINQ statement to get a collection of data from a table. I need data from other related tables, to get the set I am looking for. I am using Entity Framework 6. Am I way off on this? I could use some help sorting this out. I have masked my code for business reasons, so the table names and values are fake:</p>
  
  <pre><code>var result = POLICY_Record
                             .Include(pt =&gt; pt.POLICY_Primer)
                             .Include(pt =&gt; pt.POLICY_Primer.LOOKUP)
                             .Where(pt =&gt; pt.LOOKUP.ABBREV == "XXX")
                             .Where(pt =&gt; pt.DATE &gt;= startDate &amp;&amp; pt.DATE &lt;= endDate)
                             .Where(pt =&gt; pt.LOOKUP.TYPE == "Y")
                             .Where(pt =&gt; pt.STATUS == 1)
                             .Where(pt =&gt; !excludedTransTypes.Contains(pt.FK_Value))
                             .Where(pt =&gt; stateconfigs.Contains(pt.STATE))
                             .ToList();
  </code></pre>
  
  <p>My issue is that that there may be more than 1 <strong>Policy_Record</strong> records per <strong>Policy_Primer</strong>. When I run it like this, I have to dig deep to get the actual results. I have to iterate through the results to pull the Primer record and then get the Policy Records. </p>
  
  <p>If I include search for a single Primer ID, I get the collection of Records for that id right away. If I don't, I am forced to iterate.</p>
  
  <pre><code>var result = POLICY_Record
                             .Include(pt =&gt; pt.POLICY_Primer)
                             .Include(pt =&gt; pt.POLICY_Primer.LOOKUP)
                             .Where(pt =&gt; pt.LOOKUP.ABBREV == "XXX")
                             .Where(pt =&gt; pt.DATE &gt;= startDate &amp;&amp; pt.DATE &lt;= endDate)
                             .Where(pt =&gt; pt.LOOKUP.TYPE == "Y")
                             .Where(pt =&gt; pt.STATUS == 1)
                             .Where(pt =&gt; !excludedTransTypes.Contains(pt.FK_Value))
                             .Where(pt =&gt; stateconfigs.Contains(pt.STATE))
                             .Where(pt =&gt; pt.POLICY_Primer.NUMBER == Num)
                             .ToList();
  </code></pre>
  
  <p>Oddly, If I mouse over the result variable, it lists it as a <strong>List of POLICY_Record</strong>. Am I just doing this in the wrong order? If I start with the Primer, the where conditions fail and I cannot find a way to get them back.</p>