I have entities with compound ids in my collection: {_id: {_id: guid, version: int}}. When I need to query for latest versions of objects with some guid identificators i use following LINQ query:
Collection.AsQueryable()
.Where(x => ids.Contains(x.Id.Id))
.OrderByDescending(x => x.Id.Version)
.GroupBy(x => x.Id.Id)
.Select(x => x.First())
.Select(x => new
{
Id = x.Id.Id,
Title = x.Title
}).ToList();
With 2.3 driver version it works when I make projection in the end. But when I need to extract whole object it fails with NotSupportedException:
Collection.AsQueryable() .Where(x => newIds.Contains(x.Id.Id)) .OrderByDescending(x => x.Id.Version) .GroupBy(x => x.Id.Id) .Select(x => x.First) .ToList();
I tried to workaround this with "fake" projection without success either:
Collection.AsQueryable()
.Where(x => newIds.Contains(x.Id.Id))
.OrderByDescending(x => x.Id.Version)
.GroupBy(x => x.Id.Id)
.Select(x => new
{
Entity = x.First()
})
.AsEnumerable()
.Select(x => x.Entity)
.ToList();
Any suggestions?
- related to
-
CSHARP-2071 Using Linq Aggregation to project the root document
- Closed