Aspnetboilerplate: sharing database between NET461 and Core abp projects

Created on 29 May 2018  ·  3Comments  ·  Source: aspnetboilerplate/aspnetboilerplate

trying to add a new NETCore v3.6.2 project which will share the same database with a NET461 project v3.4 but confused/blocked on the EF migration as AbpUser NETCore of v3.6.2 added some new fields below while the NET461 abp of same version 3.6.2 doesn't have these fields.

e.g. https://github.com/aspnetboilerplate/aspnetboilerplate/blob/bbcceb85193aa2f6466d7ee5262e856fd4cc24ec/src/Abp.ZeroCore/Authorization/Users/AbpUser.cs#L26

what process should I follow to make the two projects work on same database?

Most helpful comment

OK I decided to upgrade the NET 461 project to Core and thus can use same version of abp database schema with Core project. Here's summary of what I have tired:

Current: NET461, Abp 3.4 + ModuleZero + EF
New: Core, Abp 3.8 + ModuleZero + EF Core
Challenge:

  1. ModuleZero 3.8 has new migration since 3.4, so there will be db schema change exception if migrate to Core Abp 3.8 directly
  2. EF Core use Snapshot to track database migration instead the migration table used by EF

How:

  1. Upgrade database to version of latest NET461 abp 3.8
    a. Upgrade nugets of current project to 3.8
    b. Add-Migration and Update-Database
  1. Upgrade database schema from NET461 abp 3.8 to Core abp 3.8
    a. download latest net461 template (3.8)
    b. replace Abp.Zero with Abp.ZeroCore and Abp.EntityFramework with Abp.EntityFrameworkCore
    c. change the MyProjectDBContext to inherits from AbpDbContext and put all module zero entities as DbSet in MyProjectDBContext.
    d. Add-Migration to generate the migration file from NET461 abp 3.8 to Core abp 3.8
    e. generate sql script of this migration and run against the Current project database

  2. Migrate to EF Core from EF
    a. download latest core template (3.8)
    b. delete all migrations in the template
    c. add entities from Current NET461 project to this Core project and DbSet in db context file.
    d. Add-Migration to create the migration and the EF Core snapshot file
    e. empty the Up and Down method in the migration file (as per https://docs.microsoft.com/en-us/ef/efcore-and-ef6/porting/port-code)

  3. Move other code from Current NET461 to the new Core project

All 3 comments

I haven't tried it out on the following approach yet.

The most straight forward way will be upgrading the Abp.Zero packages to Abp.ZeroCore packages in your NET461 project.

e.g Abp.Zero -> Abp.ZerCore
Abp.Zero.EntityFramwork -> Abp.ZerCore.EntityFramework
Abp.Zero.EntityFramworkCore -> Abp.ZerCore.EntityFrameworkCore

Since netstandard2.0 is compatible with NET461, in theory, Abp.ZeroCore should be fine with net461 project.

OK I decided to upgrade the NET 461 project to Core and thus can use same version of abp database schema with Core project. Here's summary of what I have tired:

Current: NET461, Abp 3.4 + ModuleZero + EF
New: Core, Abp 3.8 + ModuleZero + EF Core
Challenge:

  1. ModuleZero 3.8 has new migration since 3.4, so there will be db schema change exception if migrate to Core Abp 3.8 directly
  2. EF Core use Snapshot to track database migration instead the migration table used by EF

How:

  1. Upgrade database to version of latest NET461 abp 3.8
    a. Upgrade nugets of current project to 3.8
    b. Add-Migration and Update-Database
  1. Upgrade database schema from NET461 abp 3.8 to Core abp 3.8
    a. download latest net461 template (3.8)
    b. replace Abp.Zero with Abp.ZeroCore and Abp.EntityFramework with Abp.EntityFrameworkCore
    c. change the MyProjectDBContext to inherits from AbpDbContext and put all module zero entities as DbSet in MyProjectDBContext.
    d. Add-Migration to generate the migration file from NET461 abp 3.8 to Core abp 3.8
    e. generate sql script of this migration and run against the Current project database

  2. Migrate to EF Core from EF
    a. download latest core template (3.8)
    b. delete all migrations in the template
    c. add entities from Current NET461 project to this Core project and DbSet in db context file.
    d. Add-Migration to create the migration and the EF Core snapshot file
    e. empty the Up and Down method in the migration file (as per https://docs.microsoft.com/en-us/ef/efcore-and-ef6/porting/port-code)

  3. Move other code from Current NET461 to the new Core project

  1. if you ran into runtime error of user role not found, remember to run below sql script to update the new field AbpRoles.NormalizedName

update AbpRoles set NormalizedName = UPPER(Name);

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Mehranh picture Mehranh  ·  3Comments

hikalkan picture hikalkan  ·  3Comments

vnetonline picture vnetonline  ·  3Comments

iyilm4z picture iyilm4z  ·  3Comments

apchenjun picture apchenjun  ·  3Comments