Skip to content
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

Closed
jimerino opened this issue Aug 19, 2017 · 9 comments
Closed

Why Scaffold-DbContext must build the project? #9484

jimerino opened this issue Aug 19, 2017 · 9 comments
Labels
closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. customer-reported

Comments

@jimerino
Copy link

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?

@bricelam
Copy link
Contributor

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.

@ajcvickers
Copy link
Member

@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.

@ajcvickers ajcvickers added the closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. label Aug 23, 2017
@mathewsun
Copy link

Usually i delete old model and can't generate new. Wrong functional! Generator shouldn't build project!

@mathewsun
Copy link

Only -f (force flag) help.

@bricelam
Copy link
Contributor

See #18780, there's a hidden --no-build flag that we should document for situations like this

@Kurti123
Copy link

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...

@mp123456
Copy link

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

@filmico
Copy link

filmico commented Nov 13, 2021

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:

dotnet ef dbcontext scaffold --help

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
Those are valid for PMC inside Visual Studio or the CLI / Console and also inside VsCode terminal

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
@aeslinger0
Copy link

aeslinger0 commented Feb 21, 2024

As a work-around, what I do is make sure the entities are in their own project and reference Microsoft.EntityFramework.Core.Design directly from there. That way, I can temporarily unload any other projects that have references to these entities in order to regenerate. This also helps if you have other build errors in your projects not related to EF.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. customer-reported
Projects
None yet
Development

No branches or pull requests

8 participants