我使用最新的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"
2条答案
按热度按时间6g8kf2rb1#
正如Ivan Stove上面提到的,使用dbcontext scaffold
--use-database-names
参数。这将从表名和字段中删除下划线等内容。下面是一个使用终端的例子:
备注:
-o Models
:解决方案中要写入模型文件的文件夹。它必须已经存在。-t Individual table
:这很方便,因为您只需要生成表的一个子集的模型。只需为每个表重复-t
dgiusagp2#
这在EF的最新版本中已得到修复。使用
-UseDatabaseNames
选项在这里Scaffold-DbContext is not generating column as same in Table