Scaffold-DbContext to different output folder

Yes, you can do that with my "EF Core Power Tools" free Visual Studio extension:

https://github.com/ErikEJ/SqlCeToolbox/wiki/EF-Core-Power-Tools


It is now possible to redirect the generated context with -ContextDir option:

-ContextDir The directory to put DbContext file in. Paths are relative to the project directory.

So in your case it would be something like this:

Scaffold-DbContext "*connection*" "*provider*" -OutputDir "BackendProject" -ContextDir "DbContexts"

Source: https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell


I faced a similar problem. I had my EF models in a separate project. In order to write the models there, I just used the following command:

Scaffold-DbContext "Server=[Server];Database=[Database Name];Trsted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -Project "[Project Name]" -Force 

The key for me was the -Project "[Project Name]" -Force option.

As the top answer indicates, if you want a different folder within that project, you can just use the -OutputDir option.