postgresql Scaffold-DbContext:在.NetCore中从postgres数据库生成上下文时消除下划线

dzhpxtsq  于 2023-10-18  发布在  PostgreSQL
关注(0)|答案(2)|浏览(239)

我使用最新的EFCore版本与Postgres数据库,使用DB First方法。当从现有的Postgres数据库生成Dbcontext时,它会从表名和列名中删除下划线('_')。
Database table structure
Generated DbContext model structure
我使用以下命令来生成DbContext:
Scaffold-DbContext "Server=localhost;Port=5432;User Id=postgres;Password=mypassword;Database=SAMPLE_db;" Npgsql.EntityFrameworkCore.PostgreSQL -o DbModels -Schemas "local_dev"

6g8kf2rb

6g8kf2rb1#

正如Ivan Stove上面提到的,使用dbcontext scaffold --use-database-names参数。这将从表名和字段中删除下划线等内容。
下面是一个使用终端的例子:

  1. dotnet ef dbcontext scaffold "server=*SQL Server name*;user=*user name*;password=*password*;database=*database name*" Microsoft.EntityFrameworkCore.SqlServer -o Models -t *table name 1* -t *table name 2* -t *table name x* -f **--use-database-names**

备注:

  • -o Models:解决方案中要写入模型文件的文件夹。它必须已经存在。
  • -t Individual table:这很方便,因为您只需要生成表的一个子集的模型。只需为每个表重复-t
dgiusagp

dgiusagp2#

这在EF的最新版本中已得到修复。使用-UseDatabaseNames选项
在这里Scaffold-DbContext is not generating column as same in Table

相关问题