I'm evaluating blazor grid component. I have huge dataset (big table) which is accessed with EF core. I cannot find and good example how to correctly configure grid component with IQueriable data.
What i've tried:
I have Db context, where I have defined db set for example:
public DbSet<Partner> Partners { get; set; }On Page I have injected context, configured grid/with data this way:
<SfGrid TValue="Partner" DataSource="@data"...
@code {
IQueryable<Partner> data = null;
protected override async Task OnInitializedAsync()
{
data = context.Partners;
}
}
On first load of page everything looks fine. Data is loaded and visible in grid. But when I try to go to next data page in grid i get error:System.InvalidOperationException:
A second operation was started on this context before a previous operation completed. This is usually caused by different threads concurrently using the same instance of DbContext. For more information on how to avoid threading issues with DbContext, see https://go.microsoft.com/fwlink/?linkid=2097913.
at Microsoft.EntityFrameworkCore.Internal.ConcurrencyDetector.EnterCriticalSection()
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.MoveNext()
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
at Syncfusion.Blazor.Grids.SfGrid`1.OnHybridParametersSet()
at Syncfusion.Blazor.Grids.SfGrid`1.OnParametersSetAsync()
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
So my question is. How to correctly configure blazor datagrid with EF dbset for with IQueriable (of course I don't want to copy whole table to List<data> before attaching to grid...).
It looks that I can manage this well (connecting grid to IQueriable) with custom DataAdaptor as described on https://blazor.syncfusion.com/documentation/datagrid/custom-binding
Hi. Thanks for reply. Attached example uses CustomAdaptor. This works well also for me.
Problem is that it doesn't work well if I attach grid directly to IQueryable datasource.
|
<SfGrid @ref="Grid" DataSource="@Orders" AllowPaging="true" AllowSorting="true" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update"})">
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true"></GridEditSettings>
<GridEvents OnActionBegin="ActionBeginHandler" TValue="Order"></GridEvents>
<GridPageSettings PageSize="5"></GridPageSettings>
<GridColumns>
. . .
</GridColumns>
</SfGrid>
@code{
public IQueryable<Order> Orders { get; set; }
public IQueryable<Order> NewOrders { get; set; }
SfGrid<Order> Grid;
OrderDataAccessLayer db = new OrderDataAccessLayer();
protected override void OnInitialized()
{
Orders = db.GetAllOrders().AsQueryable();
}
public async Task ActionBeginHandler(ActionEventArgs<Order> Args)
{
await Task.Yield();
}
}
|
I'm also having the problem and I need to bind an IQueryable as a data source in the grid.
I'm evaluating the Syncfusion Blazor controls and also experiencing this issue. This initial load works but if I click on a column to re-sort I get the "A second operation was started..." error (even with the await Task.Yield() in OnActionBegin). I also noticed through sql profiler that when loading the page the same query was executed six times. Please keep us posted on any resolutions/fixes.
Thanks,
Craig