[英]Entity Framework database-first approach Pascal case
I am using EF Core 3.0 with a database-first approach to Scaffold-DbContext
from a SQL Server database:我正在使用 EF Core 3.0 和数据库优先方法从 SQL 服务器数据库中访问
Scaffold-DbContext
:
dotnet ef dbcontext
scaffold "Server=***;Database=***;User Id=***;Password=****;" Microsoft.EntityFrameworkCore.SqlServer
-o Models -c "MyContext" --project=Data
When the models are generated, it uses a specified naming for the variable for example:生成模型时,它使用指定的变量命名,例如:
if the column in the database called for example例如,如果数据库中的列调用
ISBuy
becomes Isbuy
ISBuy
成为Isbuy
CategoryID
=> CategoryId
CategoryID
=> CategoryId
and this really misses up my system...这真的错过了我的系统......
Is there is a way to prevent that converting and generate variable name with the same as database or is there is a super magical way to prevent just these and use camel case as EF Core does?有没有一种方法可以防止转换和生成与数据库相同的变量名,或者是否有一种超级神奇的方法可以防止这些并像 EF Core 那样使用驼峰式大小写?
And I am not talking about the object that returned from the API because I found a lot of solutions for that case but never this one.而且我不是在谈论从 API 返回的 object,因为我找到了很多针对这种情况的解决方案,但从来没有找到这个。
Thanks谢谢
Add --use-database-names
in your .NET Core CLI,在 .NET 核心 CLI 中添加
--use-database-names
,
dotnet ef dbcontext
scaffold "Server=***;Database=***;User Id=***;Password=****;" Microsoft.EntityFrameworkCore.SqlServer
-o Models -c "MyContext" --project=Data --use-database-names
refer to参考
https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet#dotnet-ef-dbcontext-scaffold https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet#dotnet-ef-dbcontext-scaffold
--use-database-names
--使用数据库名称
Use table and column names exactly as they appear in the database.使用与数据库中出现的完全相同的表名和列名。 If this option is omitted, database names are changed to more closely conform to C# name style conventions.
如果省略此选项,数据库名称将更改为更符合 C# 名称样式约定。
Scaffold-DbContext "Server=.\SERVERNAME;Database=DBNAME;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir ENTITIESDIR -Context "NameContext" -UseDatabaseNames
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.