Migration script does not generate NUMBER with precision and scale
Posted: Thu 23 Sep 2021 06:14
Hi,
After migration to efcore 5, new migrations does not include correct datatype for number types it misses precision and scale, and it does not take into account configured ColumnType.
Previously we could add ColumnType in entity configuration and migration script would generate correct sql.
Now it does not matter if we add Precision or ColumnType to configuration, or annotation on class property.
I'm using these commands
* dotnet ef migrations add
* dotnet ef migrations script
For example we have :
public class FundValue
{
[Column(TypeName = "NUMBER(19, 2)")]
public decimal? NewVa { get; set; }
...
}
internal class FundValueEntityTypeConfiguration : IEntityTypeConfiguration<FundValue>
{
public void Configure(EntityTypeBuilder<FundValue> c)
{
c.ToTable("FundValue", "APP");
c.Property(e => e.NewVa).HasPrecision(19, 2); // does not affect generated migration script
c.Property(e => e.NewVa).HasColumnType("NUMBER(19, 2)"); // does not affect generated migration script
Generated migration - see type is "decimal" and not customized with HasColumnType
public partial class dddd0 : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<decimal>(
name: "NewVa",
schema: "APP",
table: "FundValue",
type: "decimal", // at least we can modify here
precision: 19,
scale: 2,
nullable: true);
}
Snapshot
modelBuilder.Entity("App.FundValues.FundValue", b =>
{
b.Property<decimal?>("NewVa")
.HasPrecision(19, 2)
.HasColumnType("decimal");
Generated script - NewVa is NUMBER, however it should be NUMBER(19,2) :
-- Script was generated by Devart dotConnect for Oracle, Version 9.14.1312
-- Product home page: http://www.devart.com/dotconnect/oracle
-- Database version: Oracle 19.0.0.0
-- Script date 2021-09-23 08:52:19
*******removed ***
END;/
START TRANSACTION;
/
ALTER TABLE APP."FundValue"
ADD "NewVa" NUMBER NULL/
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20210923054609_dddd0', '5.0.10')/
COMMIT;
/
After migration to efcore 5, new migrations does not include correct datatype for number types it misses precision and scale, and it does not take into account configured ColumnType.
Previously we could add ColumnType in entity configuration and migration script would generate correct sql.
Now it does not matter if we add Precision or ColumnType to configuration, or annotation on class property.
I'm using these commands
* dotnet ef migrations add
* dotnet ef migrations script
For example we have :
public class FundValue
{
[Column(TypeName = "NUMBER(19, 2)")]
public decimal? NewVa { get; set; }
...
}
internal class FundValueEntityTypeConfiguration : IEntityTypeConfiguration<FundValue>
{
public void Configure(EntityTypeBuilder<FundValue> c)
{
c.ToTable("FundValue", "APP");
c.Property(e => e.NewVa).HasPrecision(19, 2); // does not affect generated migration script
c.Property(e => e.NewVa).HasColumnType("NUMBER(19, 2)"); // does not affect generated migration script
Generated migration - see type is "decimal" and not customized with HasColumnType
public partial class dddd0 : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<decimal>(
name: "NewVa",
schema: "APP",
table: "FundValue",
type: "decimal", // at least we can modify here
precision: 19,
scale: 2,
nullable: true);
}
Snapshot
modelBuilder.Entity("App.FundValues.FundValue", b =>
{
b.Property<decimal?>("NewVa")
.HasPrecision(19, 2)
.HasColumnType("decimal");
Generated script - NewVa is NUMBER, however it should be NUMBER(19,2) :
-- Script was generated by Devart dotConnect for Oracle, Version 9.14.1312
-- Product home page: http://www.devart.com/dotconnect/oracle
-- Database version: Oracle 19.0.0.0
-- Script date 2021-09-23 08:52:19
*******removed ***
END;/
START TRANSACTION;
/
ALTER TABLE APP."FundValue"
ADD "NewVa" NUMBER NULL/
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20210923054609_dddd0', '5.0.10')/
COMMIT;
/