带LINQ的.NET驱动程序:NotSupportedException:$ project或$ group

Dav*_*New 8 mongodb mongodb-query mongodb-.net-driver

以下查询有效:

return Database
    .GetCollection<MyEntity>()
    .AsQueryable()
    .Where(x => x.StartDate <= instance && x.EndDate >= instance)
    .GroupBy(x => x.Key.Guid)
    .Select(x => x.First().Id)
    .ToList();
Run Code Online (Sandbox Code Playgroud)

但是,当添加$ in条件(见下文)时,抛出以下异常:

应用程序抛出了未处理的异常.System.NotSupportedException:$ project或$ group不支持First({document} {_ id})

return Database
    .GetCollection<MyEntity>()
    .AsQueryable()
    .Where(x => guidKeys.Contains(x.Key.Guid)) // $in condition
    .Where(x => x.StartDate <= instance && x.EndDate >= instance)
    .GroupBy(x => x.Key.Guid)
    .Select(x => x.First().Id)
    .ToList();
Run Code Online (Sandbox Code Playgroud)

我知道驱动程序尚不支持很多LINQ,但我无法理解如何引入添加匹配阶段(使用$ in)可能导致分组阶段不兼容.

有人能够解释为什么会这样吗?

我使用MongoDB 3.2和.NET驱动程序2.2.2.

编辑:

MyEntity 看起来像这样:

[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;
    }
}
Run Code Online (Sandbox Code Playgroud)