Update Persistence project

Open Northwind.sln solution.

Update data types

Fix SQL data types in all files under Src/Persistence/Configuration folder using the following data type mappings between SQL Server and PostgreSQL:


SQL Server PostgreSQL
ntext text
image bytea
datetime timestamp

For example,

builder.Property(e => e.Description).HasColumnType("ntext");

should be changed to

builder.Property(e => e.Description).HasColumnType("text");

Manage Nuget Packages

Remove Microsoft.EntityFrameworkCore.SqlServer Nuget package from the Persistence project.

SQL Nuget

Add Npgsql.EntityFrameworkCore.PostgreSQL Nuget package to the Persistence project (version 3.1.2)

Please use version 3.1.2 and not the latest version.

Postgre Nuget

Change database provider

Update Persistence/DependencyInjection.cs file:

services.AddDbContext<NorthwindDbContext>(options =>

Update DesignTimeDbContextFactoryBase.cs file:

private const string ConnectionStringName = "NorthwindPostgreDatabase";

Update migrations

Remove existing migrations (delete Persistence/Migrations folder).

In order to run following commands, you should be inside Src/Persistence folder.

Recreate migrations:

dotnet ef migrations add InitialPostgre

Apply migrations to the database:

dotnet ef database update

You should see an output that migration was applied successfully:

Build started...
Build succeeded.
DesignTimeDbContextFactoryBase.Create(string): Connection string: 'Server=northwind-postgresql.cluster-cn0kwmvargy2.eu-west-1.rds.amazonaws.com;Database=NorthwindTraders;Username=adminuser;Password=Admin12345?'.
Applying migration '20210329131847_InitialPostgre'.