且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何防止Entity Framework Core 2.0重命名生成的类中的表和列(数据库优先)

更新时间:2023-02-06 17:34:44

-UseDatabaseNames 选项用于保留与数据库中的名称完全相同的名称(如果不是,则仅进行较小的更正).t个有效的C#标识符).

The -UseDatabaseNames option is intended to preserve the names exactly as they are in the database (with only minor corrections if they aren't valid C# identifiers).

不幸的是,此选项在版本2.0中没有使用 Scaffold-DbContext 命令(问题#9146 ),并且它不适用于属性名称(问题#9820 ).您必须等待EF Core 2.1正常使用.如果您想尽快尝试,可以随时使用每晚的构建.

Unfortunately, this option got left off the Scaffold-DbContext command in version 2.0 (issue #9146) and it wasn't applied to property names (issue #9820). You'll have to wait for EF Core 2.1 to use it as it was intended. If you're eager to try it sooner, you can always use the nightly builds.