Devart.Data.PostgreSql.Entity.EFCore not marking int keys as serial when generating migration script

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
jamir.araujo
Posts: 9
Joined: Wed 13 Mar 2019 17:25

Devart.Data.PostgreSql.Entity.EFCore not marking int keys as serial when generating migration script

Post by jamir.araujo » Wed 13 Nov 2019 17:26

Hey, I'm having to make some customizations on EntityFrameworkCore to allow the generation, and execution of migrations scripts with dynamic schema.

The central idea is that migrations will be created at development time without schema, than some time latter will be executed several times with different schema, that will be set as the default schema for model of the DbContext at runtime.

To allow that, I had to replace the IMigrationsAssembly service with a custom one. My custom implementation just inheret from the default MigrationsAssembly class and override the values of the properties Schema and PrincipalSchema for all MigrationOperations from a given DbContext.

This works for the SqlServer provider, and the Npgsql provider for PostgreSQL. But I'm facing a issue with your EFCore provider.

When I have an entity with a int key, the script generated does not mark the key column as serial type.

What I was able to find, was that the CreateTableOperation has a Columns property that is a list os AddColumnOperation. This type also has a Schema property. When the Schema property of the AddColumnOperation that is resposible for the key column is set or overriden, the Create Table statement in the generated script, will not mark the key column as serial.

This Github repository has this scenario. https://github.com/jamir-araujo/DevartCustomMigration

To reproduce, open the solution, go to the Package Manager Console, select the EntityFramework.Devart.PostgreSql project, and execute the command Script-Migration -from 0 -to CreateDatabase.

This will generate a migration script with the issue described.

Now, go to the ForceSchemaMigrationsAssembly class that is on the EntityFramework.Devart.PostgreSql projetct, uncomment the line if (addColumnOperation.Name != "Id") and execute the previous Script-Migration command again.

This time the migration script is correct.

Shalex
Site Admin
Posts: 9255
Joined: Thu 14 Aug 2008 12:44

Re: Devart.Data.PostgreSql.Entity.EFCore not marking int keys as serial when generating migration script

Post by Shalex » Fri 15 Nov 2019 15:52

Thank you for your report. We will investigate the issue and notify you about the result.


Shalex
Site Admin
Posts: 9255
Joined: Thu 14 Aug 2008 12:44

Re: Devart.Data.PostgreSql.Entity.EFCore not marking int keys as serial when generating migration script

Post by Shalex » Tue 14 Jul 2020 18:36

The investigation is in progress. An approximate timeframe for the fix is one month.


Shalex
Site Admin
Posts: 9255
Joined: Thu 14 Aug 2008 12:44

Re: Devart.Data.PostgreSql.Entity.EFCore not marking int keys as serial when generating migration script

Post by Shalex » Fri 25 Dec 2020 12:49

Sorry for the delay in providing the fix. We are going to solve the issue in January 2021.

Shalex
Site Admin
Posts: 9255
Joined: Thu 14 Aug 2008 12:44

Re: Devart.Data.PostgreSql.Entity.EFCore not marking int keys as serial when generating migration script

Post by Shalex » Fri 15 Jan 2021 14:50

The new metadata to describe autoincremental columns via annotations in EF Core Code-First Migrations are implemented in dotConnect for PostgreSQL v7.20.1812: viewtopic.php?f=3&t=44357.

The previous code generation by EF Code-First Migrations for autoincremental column:

Code: Select all

            migrationBuilder.CreateTable(
                // [...]
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false),
                    // [...]
                },
The current code generation:

Code: Select all

            migrationBuilder.CreateTable(
                // [...]
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("Devart.Data.PostgreSql:Autoincrement", true),
                    // [...]
                },

Post Reply