GithubHelp home page GithubHelp logo

Comments (2)

mkArtakMSFT avatar mkArtakMSFT commented on June 2, 2024

Thanks for bringing this up, @sbwalker.
Have you seen my response in #54539 (comment)? Maybe that addresses this too?

from aspnetcore.

sbwalker avatar sbwalker commented on June 2, 2024

@mkArtakMSFT I don't think it does address the issue. I am developing Static Server-Side components and when I use EF Core for data access I was running into exceptions:

"System.InvalidOperationException: There is already an open DataReader associated with this Connection which must be closed first."

I consulted the documentation which mentions "server-side Blazor apps":

"In server-side Blazor apps, DbContext isn't thread safe and isn't designed for concurrent use. The existing lifetimes are inappropriate for these reasons:

  1. Singleton shares state across all users of the app and leads to inappropriate concurrent use.
  2. Scoped (the default) poses a similar issue between components for the same user.
  3. Transient results in a new instance per request; but as components can be long-lived, this results in a longer-lived context than may be intended.

By default, consider using one context per operation. The context is designed for fast, low overhead instantiation:

using var context = new MyContext();
return await context.MyEntities.ToListAsync();"

So I modified my code to use DbContextFactory and it fully resolved my issue.

So in my experience DbContextFactory needs to be used in Static Server-Side Blazor as well as Interactive - Blazor Server scenarios.

from aspnetcore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.