Accessing a table with values: Id ImageId Score . Need to get the highest score of each simular ImageId.
Ex:
1 a1 10 points
2 a1 30 points
3 b1 15 points
Want: a1 30 points and b1 15 points
Code used:
public async Task<List<HistoryEntry>> Handle(Request request, CancellationToken cancellationToken)
=> await _db.History.GroupBy(a => a.ImageId).Select(s => s.OrderByDescending(x => x.Score).First()).ToListAsync();
}
Error:
.OrderByDescending(x => x.Score)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
InvalidOperationException: The LINQ expression 'GroupByShaperExpression: KeySelector: h.ImageId, ElementSelector:EntityShaperExpression: EntityType: HistoryEntry ValueBufferExpression: ProjectionBindingExpression: EmptyProjectionMember IsNullable: False .OrderByDescending(x => x.Score)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.