Comments (12)
Good suggestion, but you can just use the constructor that takes an optionsbuilder
from efcorepowertools.
The constructor is public DbContext(DbContextOptions options)
, so it is doesn't give access to the builder.
from efcorepowertools.
I meant DbContextOptions that you can build externally..
from efcorepowertools.
@ErikEJ Can you give an example of what you mean? I ran into the same problem. I would have a partial class that generates OnConfiguring, however, every time I run EF Power Tool, the generated file gets OnConfiguring added again.
So, you're saying, I could just do public DbContext(DbContextOptions options)
on my non-generated partial file and configure my options there? If done so, optionsBuilder.IsConfigured will be set to true on OnConfiguring?
from efcorepowertools.
Just add:
public DataContext(DbContextOptions<DataContext> options)
: base(options)
{
}
(This is automatically included in the latest daily build)
from efcorepowertools.
@ErikEJ I'm still not following how that is equivalent to allowing us to override OnConfiguring
ourselves. Are you suggesting doing this?
//In partial class...
//User-defined constructor
public MyContext() : this(getOptions()) { }
private static DbContextOptions getOptions()
{
var builder = new DbContextOptionsBuilder();
//Do something here with builder
return builder.Options;
}
That seems like a lot of plumbing for people to write just to get to an DbContextOptionsBuilder
.
The OnConfiguring
method generated by the handlebars template is literally useless- I don't understand why it exists or why you can't just remove it.
from efcorepowertools.
Whoa? Why do you mention Handlebars now?
from efcorepowertools.
Please provide a sample project, and indicate if you were using Handlebars or not.
from efcorepowertools.
@ErikEJ I think you are missing the point- why does OnConfiguring exist in the generated code?
It does literally nothing, except make this tool less useful because the user cannot provide their own implementation.
Handlebars has nothing to do with it- the output is the same is the same with or without it. I have included handlebar templates in my project only so that I can remove the generated OnConfigured
method. I've made no other changes to the templates.
from efcorepowertools.
I assume you have selected the option to remove the connection string?
from efcorepowertools.
The generated DbContext (not using HandleBars) has this constructor:
public DataContext(DbContextOptions<DataContext> options)
: base(options)
{
}
Which allows you to construct a context like this from outside the generated code:
public DataContext Create(string connectionString = null)
{
var optionsBuilder = new DbContextOptionsBuilder<DataContext>();
optionsBuilder.UseInMemoryDatabase(_guid);
var context = new DataContext(optionsBuilder.Options);
return context;
}
from efcorepowertools.
Closing but a well tested PR for this will be accepted
from efcorepowertools.
Related Issues (20)
- Command line usage documentation HOT 2
- Map Postgres stored procedures and functions HOT 1
- Eager Loading (Include) Not Working with reverse engineer, it returning related entity as empty {} HOT 1
- Crashed for create reverse engineering for PostgreSQL HOT 4
- T4 Template not found? HOT 14
- Oracle - reverse engineering - Database objects are still processing and not displayed at all HOT 1
- Duplicated configuration classes when using EntityTypeConfiguration.t4 HOT 10
- can't install on Microsoft Visual Studio Enterprise 2022 (ARM 64-bit) - Current Version 17.9.5 HOT 4
- SQL Server procedures - named parameters HOT 3
- Table Renaming is not working (or im doing wrong?) HOT 6
- #nullable -annotations not set for procedures HOT 9
- Unable to get result set shape for dbo.SP_* HOT 2
- Project table relationships are not generating correctly HOT 1
- Stored Procedures stopped working in new version HOT 5
- Is the Entity Id navigation property name convention changed? HOT 18
- Add Server Explorer launch button to localized VS versions
- Add an advanced option to add .HasColumnName() to every single property during Reverse Engineering HOT 8
- Add an option to strip a prefix from Model names during Reverse Engineering HOT 2
- Add Visualize DB Schema context menu to Server Explorer
- SqlLite computed columns HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from efcorepowertools.