I've recently upgraded from ASP.NET-Core 2.2 to ASP.NET-Core 3.1. I have quantities that are strings (most are just numbers but we have some that are 100 Feet, 1 Spool, etc...) In 2.2 I could sort these by using PadLeft, but this throws an error in ASP.NET-Core3.0 and above. Does anyone know a good workaround for using LINQ queries which sort numbers that are strings? (so you don't get "999", then "99", then "888", "88", etc...)
My old solution was:
IQueryable<InventoryItem> Items;
Items = from m in _context.Inventory.Where(m => m.Removed == 0)
select m;
case "Quantity":
Items = Items.OrderByDescending(s => s.Quantity.PadLeft(maxlen, '0'));
break;
This no longer works because ASP.NET-Core 3.1 evaluates it at the server instead of at client. It doesn't understand .PadLeft()
Added: I am paginating, so the query is running on this line:
items = await source.Skip(
(pageIndex - 1) * pageSize)
.Take(pageSize).ToListAsync();
If I go toList before then, I'm not limiting the results from the query to the number of results chosen...