0
votes

I need to successfully do database first connect data from postgresql to a c# project with dot net core and using entity framework core. Am familiar with mvc with sql and entity framework full database first (in this case we use the Entity Data Model Wizard which makes things easier. I am not familiar with EFcore, dot net Core and also postgresql. I successfully did a code first connect data from postgresql to a c# project with dot net core and using entity framework core, and using npgsql, on a console app. Now I need to do database first web application, and should I try to edit my existing code first console app to try database first? Or should I build a new mvc project from scratch? Also, if I do from scratch, what will be a good sequence I try eg 1. try entity framework core tutorial first (which uses sql and is only code first), then2. try to see how to do database first using reverse engineering then3. try to replace the sql with postgresql

or are there any other methods that are better?

1

1 Answers

2
votes

Scaffolding works with postresql. Create project which will have your database entities and context. Install efcore tools and npgsql for this project. Then, inside new project try this command using cmd:

dotnet ef dbcontext scaffold "Host=localhost;Database=databaseName;Username=user;Password=password" Npgsql.EntityFrameworkCore.PostgreSQL -t table1 -t table2 -o outputFolder

You dont have to pass -t parameters if you want to scaffold whole database. If some error happens, try --force argument.

You should be able to use this database via context created by ef core.