Blazor Server - EF Core wierd issue

Cenk 1,026 Reputation points
2023-02-03T06:39:08.49+00:00

Hello,

In my Blazor Server application, I am updating OrderDetails as follows.

public async Task UpdateReportAsync(List<OrderDetail> reports)
{
    _db.UpdateRange(reports);
    await _db.SaveChangesAsync();

}

So far so good, when I check the database I see data is updated. Then I navigate to another page that displays all of the orders and details, but for some reason, it still shows data as not updated.

Here is the OnInitializedAsync:

protected override async Task OnInitializedAsync()
{
        user = (await _authenticationStateProvider.GetAuthenticationStateAsync()).User;

        if (!user.Identity.IsAuthenticated)
        {
            NavigationManager.NavigateTo("/Identity/Account/Login", false);
        }

        _orders = await ViewAllOrdersUseCase.ExecuteAsync(user);
        SelectedOrders = new List<Order?> { _orders.FirstOrDefault() };
                
}

Here is how _orders are populated:

public async Task<IEnumerable<Order?>> GetAllOrders(ClaimsPrincipal user)
{
            
                var result = await _db.Orders
                    .Include(d => d.OrderDetails.Where(od => od.IsActive == 1))
                    .ThenInclude(v => v.Vendor)
                    .Include(c => c.Customer)
                    .OrderByDescending(s => s.Id)
                    .ToListAsync();
                return result;
           
}

What can be the problem? Any ideas on how to solve this?

Thank you.

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
778 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,664 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.