Good morning, I'm really enjoying the DataGrid component.
I'm working on the "DataGrid InLine Editing" example.
In my application, I use only the usual Blog and Post sample tables.
I reproduced the example, focusing only on the Blog table, and everything works fine. Unfortunately, I encountered "An unhandled error has occurred" with the DataGrid component only when I read the data using AsNoTracking().
The error occurs when: after reading the data from the Blog table, I add a few more rows (just a couple are enough) and then try to delete, starting from the last inserted row.
Please note that this type of error does not occur if I don't use AsNoTracking().
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
dbContext = DbFactory.CreateDbContext();
blogs = dbContext.Blog.AsQueryable();
}
everything works fine!
Otherwise, this way, I get the error:
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
dbContext = DbFactory.CreateDbContext();
blogs = dbContext.Blog.AsNoTracking().AsQueryable();
}
I noticed that the error is caused by:
async Task DeleteRow(Blog blog)
{
Reset(blog);
if (blogs.Contains(blog))
{
dbContext.Remove<Blog>(blog);
dbContext.SaveChanges();
await blogsGrid.Reload();
}
else
{
blogsGrid.CancelEditRow(blog);
await blogsGrid.Reload();
}
}
this line:
await blogsGrid.Reload();
These are my DataGrid settings:
<RadzenDataGrid @ref="blogsGrid" AllowAlternatingRows="false" AllowFiltering="true" AllowPaging="true" PageSize="5" AllowSorting="true" EditMode="@editMode"
Data="@blogs" TItem="Blog" RowUpdate="@OnUpdateRow" RowCreate="@OnCreateRow" Sort="@Reset" Page="@Reset" Filter="@Reset" ColumnWidth="200px">