.NET driver with LINQ: NotSupportedException: $ project or $ group

The following query is executed:

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

But, adding the condition $ in (see below), the following exception is generated:

An unhandled exception was thrown by the application. System.NotSupportedException: $ project or $ group does not support 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(); 

I understand that the LINQ driver is not yet supported by the driver, but I do not understand how introducing this addition step (using $ in) can lead to incompatibility for the grouping step.

Can anyone explain why this is happening?

I am using MongoDB 3.2 with .NET Driver 2.2.2.

EDIT:

MyEntity looks something like this:

 [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; } } 
+8
mongodb mongodb-query mongodb-.net-driver
source share

No one has answered this question yet.

See related questions:

27
MongoDB C # Driver - ignore fields when binding
3
Grouping and projecting using mongodb c # driver
3
Why is my .NET EngineoDb Driver Query Awfully Slow?
2
Mongo RequestStart (). Net driver 2.0
2
MongoDB.NET driver 2.0 Builders Filter (comparing fields with an array)
one
Does the mongo server support C # drivers on the server side
one
MongoDB Grouping and Custom Project Fields
one
Joining a collection and list throws a NotSupportedException in C # Mongodb with a strongly typed driver
one
MongoDB.NET driver: grouping with first battery
0
Mongodb C # driver Linq query Group by

All Articles