简体   繁体   English

实体框架数据库优先方法 Pascal 案例

[英]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.

相关问题 在数据库优先方法中更新模型实体框架时遇到问题 - having problem with updating model entity framework in database-first approach 具有输出参数和结果集的实体框架数据库优先方法存储过程 - Entity framework database-first approach stored procedure with output parameter and result set 实体框架 - 混合模型优先和数据库优先方法? - Entity Framework - Mixing model-first and database-first approaches? 具有 SQL 服务器凭据的数据库优先实体框架? - Database-First Entity Framework with SQL Server credentials? 具有数据库优先多对多关系问题的实体框架 6 - Entity Framework 6 with Database-First Many to Many relationship problem 实体框架Pascal案例 - Entity Framework Pascal Case 迁移 - 实体框架数据库优先方法 - Migrations - Entity Framework Database First Approach 是否可以使用数据库优先的Entity Framework 6更新SQLite数据库文件? - Is it possible to update a SQLite database file using Entity Framework 6 in database-first? 实体框架数据库优先:从同一个表中访问 2 个外键名称 - Entity Framework database-first: accessing 2 foreign keys names from same table .NET 5 或 6 是否支持采用数据库优先方法和 .EDMX 的 Sqlite? - Does .NET 5 or 6 support Sqlite with database-first approach and .EDMX?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM