Hi,
I am using Blazor Server Side with Version 18.1.0.42 and a UrlAdaptor to access data for a grid using EF Core from an Azure SQL Server that is working with the controller code shown below.
However, I have some tables that will have thousands of rows and want to convert this controller to handle the sorting and paging on the SQL server instead of retrieving all the records (db.Suppliers.ToList() will retrieve all rows in the database first).
Can you let me know how to modify this controller to do the sorting and paging on the SQL server?
Kind regards,
Stuart
public class SuppliersController : ControllerBase
{
private readonly SkyNetContext db;
public SuppliersController(SkyNetContext context)
{
db = context;
}
[HttpPost]
[Route("api/[controller]")]
public Object Post([FromBody]DataManagerRequest dm)
{
var DataSource = db.Suppliers.ToList();
if (dm.Search != null && dm.Search.Count > 0)
{
DataSource = DataOperations.PerformSearching(DataSource, dm.Search); //Search
}
if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting
{
DataSource = DataOperations.PerformSorting(DataSource, dm.Sorted);
}
if (dm.Where != null && dm.Where.Count > 0) //Filtering
{
DataSource = DataOperations.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
}
int count = DataSource.Cast<Supplier>().Count();
if (dm.Skip != 0)
{
DataSource = DataOperations.PerformSkip(DataSource, dm.Skip); //Paging
}
if (dm.Take != 0)
{
DataSource = DataOperations.PerformTake(DataSource, dm.Take);
}
return dm.RequiresCounts ? new { result = DataSource, count = count } : DataSource as object;
}
}