/// <summary> /// On Get method. /// </summary> public async Task OnGetAsync(string sortOrder) { IdSort = string.IsNullOrEmpty(sortOrder) ? "id_desc" : string.Empty; NameSort = string.IsNullOrEmpty(sortOrder) || sortOrder.Equals("name") ? "name_desc" : "name"; var supplierListItems = _dataContext.Suppliers.Select(s => new SupplierInfoModel { SupplierId = s.SupplierId, Name = s.Name, ItemCount = _dataContext.Items.Count(i => i.SupplierId.Equals(s.SupplierId)) }); switch (sortOrder) { case "id_desc": Suppliers = supplierListItems.OrderByDescending(s => s.SupplierId); break; case "name": Suppliers = supplierListItems.OrderBy(s => s.Name); break; case "name_desc": Suppliers = supplierListItems.OrderByDescending(s => s.Name); break; default: Suppliers = supplierListItems.OrderBy(s => s.SupplierId); break; } await Suppliers.AsNoTracking().ToListAsync(); }