question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting to generate context with one single constructor for pooling [FEATURE REQUEST]

See original GitHub issue

EF Core supports context poling by calling AddDbContextPool<>() instead of AddDbContext<>() inside ConfigureServices() method. But this requires context to have only one single constructor with options parameter:

InvalidOperationException: The DbContext of type 'DataContext' cannot be pooled because it does not have a single public constructor accepting a single parameter of type DbContextOptions.

To workaround this I commented the following lines in local copy of EFCoreDesigner.ttinclude file:

// Output("/// <inheritdoc />"); // Output($"public {modelRoot.EntityContainerName}() : base()"); // Output("{"); // Output("}"); // NL();

It would be great to add setting for that in Entity Context section of diagram properties 😃

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rlarikcommented, May 3, 2019

something nags at me that I put that there for a reason but, of course, didn’t document it at the time so don’t remember why now

Generating a migration without a parameterless constructor results in an error: Unable to create an object of type ‘DataContext’. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

Adding the empty constructor back fixes this problem. Where in the docs have you added the information?

1reaction
msawczyncommented, Apr 28, 2019

Now that you mention it, neither do I. I’m removing that. If anyone wants it back, it can be added to their partial. I’ll put something in the docs about that - something nags at me that I put that there for a reason but, of course, didn’t document it at the time so don’t remember why now. (https://i.redd.it/hwqj7yx9vm211.jpg)

Read more comments on GitHub >

github_iconTop Results From Across the Web

The DbContext of type cannot be pooled because it does ...
The exception message is crystal clear: the context requires "a single public constructor accepting a single parameter of type DbContextOptions" ...
Read more >
Advanced Performance Topics
Context pooling works by reusing the same context instance across requests; this means that it's effectively registered as a Singleton, ...
Read more >
Use DbContextPooling to improve the performance: .Net Core ...
I have written a post for ASP Net Core 2.1 features which you can find ... is not creating new Context instance in...
Read more >
API Reference: ApolloServer
This article documents the ApolloServer class from the @apollo/server package. You can use the ApolloServer class to create an instance of Apollo Server ......
Read more >
Avoid Wrapping DbContext in Using (and other gotchas)
You can avoid a lot of problems by not putting you Entity Framework or Entity Framework Core DbContext instance in a using statement....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found