简体   繁体   English

EF Core 脚手架-dbcontext 自定义命名空间

[英]EF Core scaffold-dbcontext custom namespace

This is a follow-up to a similar question which was answered with a reference to this issue , which has since been closed and migrated to 2.1.0 milestone according to the linked page but I can't find it in there by searching for 'scaffold-dbcontext namespace'.这是对类似问题的后续行动,该问题已通过引用此问题得到回答,该问题已被关闭并根据链接页面迁移到 2.1.0 里程碑,但我无法通过搜索“找到它”脚手架 dbcontext 命名空间'。

Are there any plans to allow the namespace to be specified when calling scaffold-dbcontext?是否有计划允许在调用scaffold-dbcontext 时指定命名空间? - I'm developing something DB-first and routinely re-scaffolding the schema. - 我正在开发一些 DB-first 并定期重新构建架构的东西。 Each time I then need to search/replace [namespace].Models.Models to remove the second.Models - not a big deal by any means but if I could tell the scaffolder what namespace to use it'd be handy.每次我需要搜索/替换 [namespace].Models.Models 以删除 second.Models - 无论如何都不是什么大问题,但如果我可以告诉脚手架使用哪个命名空间,它会很方便。

(I appreciate that the scaffolder is mainly intended to be used once to migrate to code-first then never needed again but due to reasons, that's not how I'm using it.) (我很欣赏脚手架主要用于一次迁移到代码优先然后不再需要但由于某些原因,这不是我使用它的方式。)

(I would have added a comment to the original question, since this is essentially the same question but don't have enough reputation, so posted it as an answer, which was deleted, so am re-posting as a fresh question.) (我会在原始问题上添加评论,因为这本质上是同一个问题,但没有足够的声誉,所以将其发布为答案,该答案已被删除,所以我重新发布为一个新问题。)

In my case, i remarked Scaffold-DbContext works better in EF Core 3.1.5就我而言,我说 Scaffold-DbContext 在 EF Core 3.1.5 中效果更好

Scaffold-DbContext 'Server=MSSQLSEVER;Database=MyDB_TEST;Trusted_Connection=True;' Microsoft.EntityFrameworkCore.SqlServer -ContextDir MyDB -Context MyDBContext  -OutputDir MyDB\Test -StartupProject Project -Force

I Obtain something like [ProjectNamespace].MyDB.Test我获得类似 [ProjectNamespace].MyDB.Test

One answer is to move to VS 2019 16.8.0 preview / Net 5.0 preview 7 / EF Core 5.0.0 preview, which I just did - scaffolding now uses the namespace of the project, in my case.Models, which is exactly as I want it.一个答案是迁移到 VS 2019 16.8.0 预览版/Net 5.0 预览版 7/EF Core 5.0.0 预览版,我刚刚做了 - 脚手架现在使用项目的命名空间,在我的例子中是.Models,这和我完全一样想要它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 仅在 EF Core 中的 Scaffold-DbContext 存储过程 - Scaffold-DbContext Stored Procedures only in EF Core -在 Scaffold-DbContext 中无法识别命名空间选项 - -Namespace option is not recognized in Scaffold-DbContext EF Core2.2:Scaffold-DbContext无法在WPF项目中使用命名连接字符串 - EF Core2.2: Scaffold-DbContext not working with named connection string in WPF project EF Core 数据库第一种方法:Scaffold-DbContext 不被识别为 cmdlet 的名称 - EF Core Database First Approach: Scaffold-DbContext is not recognized as the name of a cmdlet EF 核心 Scaffold-DbContext 不起作用:执行超时已过期 - EF core Scaffold-DbContext doesn't work : Execution Timeout Expired EF core 3.1+Pomelo Scaffold-DbContext 防止视图代码生成 - EF core 3.1+Pomelo Scaffold-DbContext prevent view code generation 使用Scaffold-DbContext的部分EF上下文OnModelCreating - Partial EF Context OnModelCreating Using Scaffold-DbContext 使用Scaffold-DbContext时的ASP.NET Core Error - ASP.NET Core Error while using Scaffold-DbContext Scaffold-DbContext 在 .net 核心中抛出错误“找不到程序集” - Scaffold-DbContext throws error “Could not find assembly” in .net core 在ASP.NET Core中支撑现有数据库(Scaffold-DbContext) - Scaffolding existing databases in ASP.NET Core (Scaffold-DbContext)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM