I'm trying to order my IMongoqueryable collection via reflection with a property string.
Unfortunately I'm getting the message Only fields are allowed in a $sort.
private static void SetOrderBy(ref IMongoQueryable<Trade> trades, BlazorGridRequest request)
{
var prop = typeof(Trade).GetProperty(request.OrderBy);
if (request.OrderByDescending)
trades = trades.OrderByDescending(t => prop.GetValue(t));
else
trades = trades.OrderBy(t => prop.GetValue(t));
}
Can someone help me figure out, how I can get this to work? Thanks!