title: .NET Driver with LINQ: NotSupportedException: $project or $group
body: <p>The following query works:</p>
  
  <pre><code>return Database
      .GetCollection&lt;MyEntity&gt;()
      .AsQueryable()
      .Where(x =&gt; x.StartDate &lt;= instance &amp;&amp; x.EndDate &gt;= instance)
      .GroupBy(x =&gt; x.Key.Guid)
      .Select(x =&gt; x.First().Id)
      .ToList();
  </code></pre>
  
  <p>But, when adding an $in condition (see below), the following exception is thrown: </p>
  
  <blockquote>
    <p>An unhandled exception was thrown by the application.
    System.NotSupportedException: $project or $group does not support
    First({document}{_id})</p>
  </blockquote>
  
  <pre><code>return Database
      .GetCollection&lt;MyEntity&gt;()
      .AsQueryable()
      .Where(x =&gt; guidKeys.Contains(x.Key.Guid)) // $in condition
      .Where(x =&gt; x.StartDate &lt;= instance &amp;&amp; x.EndDate &gt;= instance)
      .GroupBy(x =&gt; x.Key.Guid)
      .Select(x =&gt; x.First().Id)
      .ToList();
  </code></pre>
  
  <p>I understand that a lot of LINQ is not yet supported by the driver, but I can't understand how introducing that addition match stage (using $in) could result in an incompatibility for the grouping stage.</p>
  
  <p>Is anyone able to explain why this is happening?</p>
  
  <p>I am using MongoDB 3.2 with the .NET Driver 2.2.2.</p>
  
  <h3>EDIT:</h3>
  
  <p><code>MyEntity</code> looks something like this:</p>
  
  <pre><code>[BsonIgnoreExtraElements]
  public class MyEntity: BaseMongoDocument
  {
      [BsonId]
      [BsonRepresentation(BsonType.Binary)]
      public Guid Id { get; set; }
  
      [BsonRequired]
      [BsonElement("startDate")]
      public DateTime StartDate { get; set; }
  
      [BsonRequired]
      [BsonElement("endDate")]
      public DateTime EndDate { get; set; }
  
      [BsonRequired]
      [BsonElement("key")]
      public SquidDocument Key { get; set; }
  
      [BsonConstructor]
      private MyEntity()
      { }
  }
  
  public class SquidDocument
  {
      [BsonRequired]
      [BsonElement("guid")]
      public Guid Guid { get; private set; }
  
      [BsonRequired]
      [BsonElement("squid")]
      public string Squid { get; private set; }
  
      [BsonConstructor]
      private SquidDocument(Guid guid, string squid)
      {
          Guid = realSquid.Guid;
          Squid = realSquid.Value;
      }
  }
  </code></pre>