Scaffold-DbContext to different output folder

c# entity-framework-core

Question

I'm implementing repository pattern in company solution I work for, separating model classes in a Backend project and database context and migrations in DbContexts project.

I'm using Scaffold-DbContext setting my Backend Project as default project to destination of model classes, however DbContext Class is always created in same folder as model classes. Is it possible to redirect the creation of the DbContext class to a different output folder, in my case to DbContexts project?

1
8
1/16/2018 1:21:21 PM

Popular Answer

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

8
7/25/2018 3:43:31 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow