Skip to content

Latest commit

 

History

History
36 lines (20 loc) · 1.51 KB

File metadata and controls

36 lines (20 loc) · 1.51 KB

Database First with Entity Framework Core

Simple example of Database-First approach using Entity Franework Core.

Packages required

  • Microsoft.EntityFrameworkCore.Design
  • Npgsql.EntityFrameworkCore.PostgreSQL
  • Microsoft.EntityFrameworkCore.SqlServer

CLI commands

  • dotnet ef dbcontext scaffold "Data Source=DESKTOP-P87PH2B;Initial Catalog=CodeFirstEntityFramework;Integrated Security=true;" Microsoft.EntityFrameworkCore.SqlServer -o SqlServerScaffold

  • dotnet ef dbcontext scaffold "Server=localhost;User Id=postgres;Password=postgres;Database=CodeFirstEntityFramework;" Npgsql.EntityFrameworkCore.PostgreSQL -o PostgreSqlScaffold

Use case

Consider the case when we have a connection string to some database we want to reverse engineer.

Consider the database CodeFirstEntityFrameworkCore

We have following connection strings:

  • "Server=localhost;User Id=postgres;Password=postgres;Database=CodeFirstEntityFramework;"
  • "Data Source=DESKTOP-P87PH2B;Initial Catalog=CodeFirstEntityFramework;Integrated Security=true;"

Using the commands:

  • PostgreSQL:

    dotnet ef dbcontext scaffold "Server=localhost;User Id=postgres;Password=postgres;Database=CodeFirstEntityFramework;" Npgsql.EntityFrameworkCore.PostgreSQL -o PostgreSqlScaffold

  • MS SQL Server:

    dotnet ef dbcontext scaffold "Data Source=DESKTOP-P87PH2B;Initial Catalog=CodeFirstEntityFramework;Integrated Security=true;" Microsoft.EntityFrameworkCore.SqlServer -o SqlServerScaffold