-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why Scaffold-DbContext must build the project? #9484
Comments
Primarily to allow you to register (or override) design-time services: class MyDesignTimeServices : IDesignTimeServices
{
public void ConfigureDesignTimeServices(IServiceCollection services)
=> services.AddSingleton<IPluralizer, MyCustomPluralizer>();
} There are also other pragmatic reasons, but they could (in theory) be avoided. |
@jimerino While this is not an unreasonable request it would actually take quite a lot of effort to make work and would also likely result in more fragile code since EF would have to be figuring out things like assembly locations independently. Also, hopefully an improved flow including "update model from database" (issue #831) will make this overall experience better. Closing this issue for these reasons. |
Usually i delete old model and can't generate new. Wrong functional! Generator shouldn't build project! |
Only -f (force flag) help. |
See #18780, there's a hidden --no-build flag that we should document for situations like this |
Just to give you a short response: the "Scaffold-DbContext" command has no --no-build / -no-build flag and we cannot suppress the build on scaffolding. After deleting some EF core models, I am already one hour in on bringing my code to a working state so that i can finally scaffold again. The requirement to have a buildable code state is really painful at times... |
I also wondered about that behavior but what I am doing instead of deleting the existing files I run scaffolding on other folder and after it generate the files I am coping them to model folder |
As @bricelam has stated there is a --no-build flag that actually is not hidden anymore in Core 5/6 You can check all flags using the following command:
The following two flags made the trick of overwriting your classes by also avoiding the need to delete things by hand while skipping the build process as a previous step to the scaffolding mechanism. --no-build --force If you have customized things in the dbContext Class, bare in mind to create a copy of it as it will be overwritten. MS has a pretty good explanation on many of the tricky flags in here https://docs.microsoft.com/en-us/ef/core/cli/powershell |
As a work-around, what I do is make sure the entities are in their own project and reference |
Hi!
I'm newbie and I'm trying to understand EF core. I've notice if you have an error in the project, Scaffold-DbContext returns "Build failed". Only if your project is clean and can build without errors, then Scaffold-DbContext can generate the Entities from DB.
In my sample proyects, it's very common to destroy the Entities deleting the clases and regenerating them frequently with Scaffold-DbContext.
Due I've deleted all entity clases, I must comment all lines where my DBContext and Entities appears, build without error, generate the Entities with Scaffold-DbContext and uncomment again. I think if my project was bigger, regenerating all Entities will be a tedious work.
Could it be possible that Scaffold-DbContext doesn't need to get a build project to generate the Entities?
The text was updated successfully, but these errors were encountered: