Blazor concurrency problem using Entity Framework Core

后端 未结 6 1584
半阙折子戏
半阙折子戏 2021-01-05 03:46

My goal

I want to create a new IdentityUser and show all the users already created through the same Blazor page. This page has:

  1. a form
6条回答
  •  余生分开走
    2021-01-05 04:40

    Well, I have a quite similar scenario with this, and I 'solve' mine is to move everything from OnInitializedAsync() to

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if(firstRender)
        {
            //Your code in OnInitializedAsync()
            StateHasChanged();
        }
    {
    

    It seems solved, but I had no idea to find out the proves. I guess just skip from the initialization to let the component success build, then we can go further.

    /******************************Update********************************/

    I'm still facing the problem, seems I'm giving a wrong solution to go. When I checked with this Blazor A second operation started on this context before a previous operation completed I got my problem clear. Cause I'm actually dealing with a lot of components initialization with dbContext operations. According to @dani_herrera mention that if you have more than 1 component execute Init at a time, probably the problem appears. As I took his advise to change my dbContext Service to Transient, and I get away from the problem.

提交回复
热议问题