Entityframework.docs: Document best practices for EF Core in Blazor applications

Created on 3 Jan 2020  Â·  5Comments  Â·  Source: dotnet/EntityFramework.Docs

Can MS provide guidance and code to Avoiding DbContext threading issues when using Blazor server-side?


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

area-ui-platforms closed-fixed

All 5 comments

I'm having problems here too. The documented guidance is not enough. The error happens anyway.

Not sure if this will help, but adding the code below fixed this issue for me.

'services.AddDbContext(); //MirwDbContext is the name of by DB Context'

The struggle for me at least, was sharing a dbcontext with more than 1 blazor component per page. A component and its subcomponent (and I assume other subcomponents) will run OnInitializedAsync() in parallel, leading to a concurrency error if they share the same dbcontext. Best practice then, is to design your components so they can use a separate dbcontext.
This is definitely an issue. With this still fresh in my mind, the only solutions I have come up with so far was to join everything into 1 supercomponent, or to use different dbcontexts but then orchestrate a save among them all.
I will be looking further into how to minimize the "editing" dbcontext, and using components that work with self-contained dbcontexts (and don't need to save). Definitely a big change in process, coming from Silverlight where it was fine to load everything into one great big dbcontext...

@JeremyLikness I think we can close this now, right?

@ajcvickers In my opinion, yes.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MCcoder52 picture MCcoder52  Â·  3Comments

speciesunknown picture speciesunknown  Â·  3Comments

ctaggart picture ctaggart  Â·  3Comments

CubeSpark picture CubeSpark  Â·  3Comments

ajcvickers picture ajcvickers  Â·  4Comments