I am relatively new to MongoDB and have found myself much more comfortable writing linq to extract data but when I tried this:
var fieldList = await collection.AsQueryable<Change>()
.Where(f => f.Area == area && f.AreaRecordId == id)
.GroupBy(f => f.Field)
.Select(f => f.OrderByDescending(d => d.DateChange).FirstOrDefault())
.ToListAsync();
I got the error: System.NotSupportedException: FirstOrDefault of type System.Linq.Enumerable is not supported in the expression tree { document}.OrderByDescending(d => d.DateChange).FirstOrDefault().
I understand that not every area of linq is supported.
My MongoDB stores documents of changes. Each change has among other things, an area, an area record id, field id and a date change property. For an area of specific record id, I want to be able to pull all the field changes (i.e. group by field id) but only the most recent ones.
Any thoughts how I could accomplish this? I did try with a more native MongoDB approach but got stuck straight away.