Setting to generate context with one single constructor for pooling [FEATURE REQUEST]
See original GitHub issueEF 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:
- Created 4 years ago
- Comments:8 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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?
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)