Why does using `await` EF core execute command twice
I am using Blazor server app and add EF Core
Dependency
Here is the code where query executes twice
10 Replies
how do you know that it's executing twice and that that's the reason?
i see it in the console
have you set a breakpoint on that call to make sure you aren't just calling it twice?
also, i'd just make that service return a list to avoid the double ToList
or just don't tolist it, i don't think that's a requirement for json serialization
this behaviour only occurs in
OnInitializedAsync()
https://stackoverflow.com/questions/58075628/why-are-blazor-lifecycle-methods-getting-executed-twice
Stack Overflow
Why are Blazor lifecycle methods getting executed twice?
So with a release of asp.net core 3.0 and blazor 1.0 I started doing some actual work with blazor. When splitting Blazor component code into code behind I am using the following
public class Logout...
tldr, prerendering, be careful about which methods you put your logic in
ASP.NET Core Razor component lifecycle
Learn about the ASP.NET Core Razor component lifecycle and how to use lifecycle events.
To prevent developer code in OnInitializedAsync from running twice when prerendering, see the Stateful reconnection after prerendering section. The content in the section focuses on Blazor Web Apps and stateful SignalR reconnection. To preserve state during the execution of initialization code while prerendering, see Prerender ASP.NET Core Razor components.but tbh I thought it was that it renders once from the server, and then once for the client, even on blazor server
yep this one fix my problem by changting this
to this