Reputation: 21
I am using the latest EFCore version with the Postgres database using the DB First approach. While generating Dbcontext from an existing Postgres database it eliminates underscore ('_') from the table name and also from the column names.
Generated DbContext model structure
I am using the following command to generate DbContext:
Scaffold-DbContext "Server=localhost;Port=5432;User Id=postgres;Password=mypassword;Database=SAMPLE_db;" Npgsql.EntityFrameworkCore.PostgreSQL -o DbModels -Schemas "local_dev"
Upvotes: 0
Views: 8779
Reputation: 1644
This is now fixed in latest version of EF.
Use the -UseDatabaseNames
option
see here Scaffold-DbContext is not generating column as same in Table
Upvotes: 0
Reputation: 76
As Ivan Stove mentioned above, use the dbcontext scaffold --use-database-names
argument. This will remove things like underscores from both table names and fields.
Here's an example using the terminal:
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**
Notes:
-o Models
: The folder in your solution you want the model files to be written to. It needs to already exist.
-t Individual table
: This is handy is you only want a subset of tables to have models generated.
Just repeat the -t
for each tableUpvotes: 1