title: Sql to Linq difficulty - group by, having
body: <p>I have the following query in SQL which I would like to convert to LINQ: </p>
  
  <pre><code>select profile_id from t
  where child_id in (1, 2 ,3, ...) //this will be a list of integers CHILDREN
  group by profile_id
  having count(distinct child_id) = 3
  </code></pre>
  
  <p>I am having a difficulty how to write the last line in my sql query into linq. The following is my work so far:</p>
  
  <pre><code>public IQueryable&lt;ProfileChildRelationship&gt; GetPCRelByCids(List&lt;int&gt; children)
      {
          var query = from pcr in this._entities.ProfileChildRelationships
                      where children.Contains(pcr.pcChildIDF)
                      group pcr by pcr.pcProfileIDF into g
                      ??? having ...?
                      select pcr;
  
          return query;
      }
  </code></pre>
  
  <p>I think that may main problem is that many convert a having sql statement into a where linq statement, but in my case i do not think it is possible to write another where after the group by linq statement!</p>
  
  <p>Update:</p>
  
  <p>The situation: I have a number of children, each of which has many different profiles, (some may be the same). A user will select a number of children, from which I would like to derive their common profiles. That is, if profile X is found for EVERY child, than I will get it, if profile Y is found for every child except one, than it would be invalid!</p>