chrisonstack
chrisonstack

Reputation: 185

How to use Npgsql in ASP.NET Boilerplate Core 2.0 template?

I have spent many hours trying to use PostgreSQL with ASP.NET Boilerplate Core 2.x + Module Zero (which looks awesome!).

  1. I added Npgsql.EntityFrameworkCore.PostgreSQL & Npgsql.EntityFrameworkCore.PostgreSQL.Design dependencies to myApp.EntityFrameworkCore.

  2. I also changed the connection string and I use builder.UseNpgsql instead of builder.UseSqlServer in myappDbContextConfigurer.cs.

As a new project, I started with Npgsql v2.0.0. But after a few problems, I found that this release has some issues. So I returned to the 1.1.1 release.

I'm pretty sure this part works fine. The next step is to delete all existing migrations and reload them:

When I do the first one, I get an error:

Method 'Clone' in type 'Microsoft.EntityFrameworkCore.Infrastructure.Internal.NpgsqlOptionsExtension' from assembly 'Npgsql.EntityFrameworkCore.PostgreSQL, Version=1.1.1.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' does not have an implementation.

I found a beginning of the solution here (6th post): https://forum.aspnetboilerplate.com/viewtopic.php?t=5304&p=13013

The post seems a little bit outdated and I don't know where to implement NpgsqlMigrationSqlGenerator (I mean, in which project).

Thank you for reading this post, any help will be appreciated.

Upvotes: 6

Views: 3055

Answers (1)

GeorgeDuke
GeorgeDuke

Reputation: 66

To solve your issue with the Abp Template (v3.4.0 .NET core + mvc + modulezero) you have to :

  • Uninstall the package Microsoft.EntityFrameworkCore.SqlServer
  • add Npgsql.EntityFrameworkCore.PostgreSQL (2.0.0) & Npgsql.EntityFrameworkCore.PostgreSQL.Design (1.1.1)
  • Drop ALL files in the "Migrations" directory (Project "EntityFrameworkCore/Migrations")

There're other minors changes pointed here.

Upvotes: 5

Related Questions