Blazor: A second operation started on this context before a previous operation completed

blazor blazor-server-side c# entity-framework entity-framework-core

Accepted Answer

Try setting up a fresh scope for each request:

public class MyViewModel : INotifyPropertyChanged
{

    protected readonly IServiceScopeFactory _ServiceScopeFactory;

    public MyViewModel(IServiceScopeFactory serviceScopeFactory)
    {
        _ServiceScopeFactory = serviceScopeFactory;
    }

    public async Task<IEnumerable<Dto>> GetList(string s)
    {
        using (var scope = _ServiceScopeFactory.CreateScope())
        {
            var referenceContext = scope.ServiceProvider.GetService<MyContext>();    
            return await _myContext.Table1.where(....)....ToListAsync();
        }
    }

Here, Blazor Product Manager Daniel Roth discusses Utilizing Blazor and Entity Framework Core.

5
10/11/2019 7:37:16 PM

Popular Answer

ZZZ_tmp






Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow