I'm having problem the following LINQ expression on Mongo using the 2.1 C# driver running Mongo 3.0. Selecting the Id works fine but not selecting the A.
The following simple test demonstrates the error I'm getting.
Specified method is not supported. at MongoDB.Driver.Linq.Processors.AccumulatorBinder.GetAccumulatorArgument(Expression node)
If it is not supported, any suggestions how to work around it without having to unwind the queryable first? I know that I could use the mongo aggregate framework but that is not desired since we are not exposed to that here and I do not want mongo specific syntax at this level.
[Test]
public void TestLinqSelectOnGroupBy()
{
MongoClient mongoClient = new MongoClient();
var repo = mongoClient.GetDatabase("GroupSelect");
var a = new A() { Id = "1", Group = "A" };
var col = repo.GetCollection<A>("A");
col.InsertOneAsync(a);
var allA = col.AsQueryable(); // adding .ToArray(); will obviously make it work but that is not very efficient
var works = allA.GroupBy(x => x.Group).Select(x => x.First().Id).ToArray();
var fails = allA.GroupBy(x => x.Group).Select(x => x.First()).ToArray();
}
private class A
{
public string Id { get; set; }
public string Group { get; set; }
}