Scaffold-DbContext 到不同的输出文件夹 [英] Scaffold-DbContext to different output folder

查看:25
本文介绍了Scaffold-DbContext 到不同的输出文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我工作的公司解决方案中实施存储库模式,将后端项目中的模型类与 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 类始终与模型类在同一文件夹中创建.是否可以将 DbContext 类的创建重定向到不同的输出文件夹,在我的情况下重定向到 DbContexts 项目?

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?

推荐答案

现在可以使用 -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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆