6

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:

  • Add-Migration "Initial_Migrations"
  • Add-Migration "AbpZero_Initial"

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.

aaron
  • 39,695
  • 6
  • 46
  • 102
chrisonstack
  • 175
  • 2
  • 11

1 Answers1

5

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.

GeorgeDuke
  • 66
  • 3
  • 1
    Member for 2 years and 7 months on SO, with 0 questions and this drew you out to post your first answer? Nice :) – aaron Nov 26 '17 at 17:27
  • Could you explain why the downgrade is required? – aaron Nov 26 '17 at 17:28
  • Thank you @GeorgeDuke ! Everything looks good, tables are created and the project compiles. I'm now able to go to the swagger view, even if I still have a warning when I run the migration... An error occurred while calling method 'BuildWebHost' on class 'Program'. Continuing without the application service provider. Error: 42P01: relationship « AbpEditions » does not exist – chrisonstack Nov 26 '17 at 17:55
  • @aaron : Thanks. Previously, without this downgrade, i was not able to execute the database migration instructions. But after a new test, this step is not necessary. (My previous answer is updated now) – GeorgeDuke Nov 27 '17 at 08:19
  • https://github.com/JbmOnGitHub/changeDbInAspnetboilerplate/blob/master/abptemplate_3_4_0_NETcore_mvc_modulezero.md works great – Munna Bhakta Oct 23 '18 at 12:02