Dear Support!
My virtualized DataGrid table freezes with this error:
Error: System.InvalidOperationException: A second operation was started on this context instance before a previous operation completed. This is usually caused by different threads concurrently using the same instance of DbContext.
I have tried to add ServiceLifetime.Transient to the DbContext registration,
I have tried to separat DbContext creation with DbContextFactory but when I scroll down the table stops with this error.
My general repository returns an IQueryable
public IQueryable<TEntity> GetAsync(
Expression<Func<TEntity, bool>>? filter = null,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>>? orderBy = null,
string includes = "", int skip = 0, int take = 0)
This is my query handler:
public async Task<VirtualizeResponse<UgyfelDto>> Handle(GetUgyfelListQuery request, CancellationToken cancellationToken)
{
var skip = request.LoadDataArgs?.Skip ?? 0;
var top = request.LoadDataArgs?.Top ?? 10;
Int32.TryParse(request.LoadDataArgs?.Filter ?? "", out int filterNumber);
var filterText = request.LoadDataArgs?.Filter ?? "";
var items = await _ugyfelRepository.GetAsync(
x => x.Nev!.StartsWith(filterText) || x.Id == filterNumber || x.TAJ!.StartsWith(filterText) || x.IgSzam!.StartsWith(filterText),
x => x.OrderBy(y => y.Nev),
"",
skip, top)
.Select(x => new UgyfelDto { Id = x.Id, Nev = x.Nev, SzulDatum = x.SzulDatum, TAJ = x.TAJ, IgSzam = x.IgSzam })
.ToListAsync();
var totalSize = await _ugyfelRepository.CountAsync();
return new VirtualizeResponse<UgyfelDto> { Items = items, TotalSize = totalSize };
}
And how I call it:
string? lastfilter;
async Task LoadData(Radzen.LoadDataArgs args)
{
await Task.Yield();
if (!string.IsNullOrEmpty(args.Filter) && lastfilter != args.Filter)
{
args.Skip = 0;
}
var data = await Mediator!.Send<VirtualizeResponse<UgyfelDto>>(new GetUgyfelListQuery
{
LoadDataArgs = new LoadDataArgs { Skip = args.Skip, Top = args.Top, Filter = args.Filter, OrderBy = args.OrderBy }
});
ugyfelek = data.Items;
count = data.TotalSize;
}
Can you help me with some advise, please?