Hello.
- I used the RadzenDataGrid Performance example to implement reading data from EF Core dbContext. It somehow works. But without Take(20) it reads whole data table and when I add Take(20) it just reads 20 records and do not read another page.
My code is almost identical to the one in example, where another pages are generated:
RadZenDataGrid Performance example
Here is my result and the code:
records = from dl in dlContext.Dls.Take(20)
select new Statistics()
{
GUID = dl.Guid,
Import = dl.Import,
CreatedBy = dl.CreatedBy,
CreatedOn = dl.CreatedOn,
StartedOn = dl.StartedOn,
CompletedOn = dl.CompletedOn,
FileName = dl.FileName,
InstantRun = dl.InstantRun,
StatusCode = dl.StatusCode,
Success = 15,
Failed = 2,
Totals = 17
};
- Is there any way to generate count of records from another table in this query? Like "SELECT COUNT(*) FROM {tableName} WHERE ImportGuid = {dl.Guid} and StatusCode = 2" ? I used some approaches, but always ended with performance issue.
The Take(20)
in the linked demo is used for test purposes - just to create the 50000 records in memory. You should not call it in your real application. Instead you should set the Data property of your RadzenDataGrid to an IQueryable obtained from your EF context. Paging will happen automatically if it is enabled and only one page of data will be retrieved.
You can get the total count however you want. Not sure why you are getting performance issues - you can profile your application to see which query is the bottleneck.
Well, my problem is a bit complex. To display the 25000 of records to IQueryable/IEnumerable/List from one table as showed in my post. But the last three columns are the real problem - Success/Failed/Totals. I have to do something like this:
statusCount.Successful = dlContext.DlAccountAnonymizes.Where(s => s.ImportGuid == item.GUID && s.StatusCode == (int)ImportStatus.Successful).Count();
Unfortunately, I have to dynamically change the sub table to get data from the correct import type table. If I use Take{20}, the result is sufficient. But when I delete it, the count takes minutes.
That's why I think, the whole bunch of data is loaded to memory and the RadzenDataGrid just shows it as pages.
RadzenDataGrid never loads the whole data in memory when paging is enabled. I think your query which calculates count is slow for whatever reason - you can probably check that with profiling. You can also hardcode the Count value and see if it makes a difference.
Well, You are right, that the count is quite slow. But when I have Take(20) in my select from dbContext, it takes just the 20 records and then counts the fields to these records. It takes about 2s time. But when I remove the Take(20), it takes ages becouse it counts not the 20 records mentioned as parameter in the RadzenDataGrid, but whole bunch of 20 thousands of records.
Normally Count() is quite fast even for 20k items. It translates to SELECT COUNT(*)
. The Count should be set to the total number of items otherwise paging will not work.