title: Linq to Entities over EF 4 on SQL Server 2005
body: <blockquote>
    <p>'Cannot compare elements of type 'System.Collections.Generic.ICollection`1'. Only primitive types (such as Int32, String, and Guid) and entity types are supported.'</p>
  </blockquote>
  
  <p>Entities &amp; Relationships (Navigation Properties):</p>
  
  <pre><code>Case (1 &lt;-&gt; ∞) MeetingCase (1 &lt;-&gt; ∞) MeetingCaseOutcomes
  </code></pre>
  
  <p>The offending code is:</p>
  
  <pre><code>IQueryable&lt;Case&gt; cases; // this is obviously attached to a context and able to access data)
  var broken = cases
     .Where(c =&gt; c.MeetingCases
        .Where(mc =&gt; mc.ExpectedStartDateTime &lt;= DateTime.Now)
           .Any(m =&gt; m.MeetingCaseOutcomes == null || m.MeetingCaseOutcomes.Count == 0));
  </code></pre>
  
  <p>I assume the problem is due to lack of support for the 'Any' operator, though I had thought this would work in EF 4 (since support for the related 'Contains' operator has been added).</p>
  
  <p>How should I re-structure this call to produce what I want?</p>
  
  <p>I have been working with EF for several months now and understand many of the runtime gotchas</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>The Where clause above does contain a predicate, as follows:</p>
  
  <pre><code>c.MeetingCases.Where(mc =&gt; mc.ExpectedStartDateTime &lt;= DateTime.Now)
                .Any(m =&gt; m.MeetingCaseOutcomes == null || m.MeetingCaseOutcomes.Count == 0)
  </code></pre>
  
  <p>Because <code>Any</code> returns a boolean, the whole thing produces a predicate expression.</p>
  
  <p>Also, the intent of this logic is to return a set of Case objects which do not have MeetingCaseOutcome records for any MeetingCase records where the meeting has already taken place (hence the comparison to DateTime.Now). This is part of a meeting scheduling system, and this is to check that Outcomes from each meeting are entered into the system following the meeting taking place.</p>