Maverick (Shaun)
Invoke StateHasChanged() only after asynchronous operation has completed
Referring to the code below:
My intent is to refresh the page after updating the database, in order to display the updated information. Based on the behaviour I am seeing, it looks as if
StateHasChanged()
is invoked before the database is updated with await DrawService.ActivateDraw(DrawId)
. What would be the correct way to refresh the page only after the await
is complete?20 replies
Multiple Blazor components accessing database via single DbContext at same time
What is the most straightforward way to handle multiple Blazor components trying to access the database via a DbContext in EF Core at once? I'm creating an indeterminate number of components on a page at once that all make a call within
OnInitializedAsync()
to a scoped service in order to pull a record from the database. A problem seems to arise from the fact that they are all using the same DbContext, which is not thread safe? Can someone point me in the right direction? Hopefully that's not too broad a question, still new to this area .21 replies
Using IdentityCore with InteractiveServer rendermode (Blazor .NET 8)
I've realised that the IdentityCore login/register pages do not work with InteractiveServer rendermode. I've worked around this by setting the rendermode conditionally rather than globally (InteractiveServer for everything BUT these pages). However, that of course breaks the interactivity of my MainLayout navigation. Can anyone suggest a good way to approach this problem? Ideally, I'd like to use the default login/register pages (with a few tweaks) and have the interactivity of MainLayout still work. I'm a newcomer to Blazor and .NET so I'm not sure what my options are. Any advice is welcome, thanks in advance.
11 replies
Default parameter values in primary constructor
I've created a data model class for use with Entity Framework Core, and I just had a question regarding my use of a primary constructor here. As you can see,
IsActive
and Prizes
are both being initialized to default values. Will this give me the same behaviour as if I'd used an old-school constructor? (i.e. public RaffleModel(...)
... you know the drill)
Additionally, are there any considerations I need to have specifically relating to how Entity Framework Core will interact with this class?
55 replies