Scaffold-DbContext到不同的输出文件夹 [英] Scaffold-DbContext to different output folder
问题描述
我正在工作的公司解决方案中实现存储库模式,将后端项目和数据库上下文中的模型类以及DbContexts项目中的迁移分离。
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.
使用Scaffold-DbContext将后端项目设置为模型类目标的默认项目,但是DbContext类始终与模型类创建在同一文件夹中。
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?
推荐答案
它可以将DbContext类的创建重定向到其他输出文件夹(在我的情况下重定向到DbContexts项目)吗?现在可以使用-ContextDir选项重定向生成的上下文:
It is now possible to redirect the generated context with -ContextDir option:
-ContextDir 放置DbContext文件的目录路径是相对于项目目录的。
-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"
来源: https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell
这篇关于Scaffold-DbContext到不同的输出文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!