无法将现有列设置为空

问题描述 投票:1回答:1

我将现有属性decimal设置为decimal?

    public decimal? TotalAmountTTC { get; set; }

然后我用add-migration创建了一个迁移,它为此生成了我:

        migrationBuilder.AlterColumn<decimal>(
            name: "c0003_total_amount_ttc",
            table: "t0003_transfer_request",
            type: "decimal(13,4)",
            nullable: true,
            oldClrType: typeof(decimal),
            oldType: "decimal(13,4)");

但是我执行update-database后,该列仍为not nullable

enter image description here

当我运行script-migration来检查生成的SQL时,我们可以清楚地看到它并不在乎我的属性现在可以为空:

        ALTER TABLE "t0003_transfer_request" MODIFY "c0003_total_amount_ttc" decimal(13,4)
        /

我做错什么了吗?这是一个错误吗?

我尝试在映射中设置IsRequired(false),但结果相同。

         builder.Property(tr => tr.TotalAmountTTC).HasColumnName("c0003_total_amount_ttc").IsRequired(false);
oracle entity-framework ef-fluent-api
1个回答
0
投票

好吧,对我来说这似乎像是一个[[hack,但是我找到了一种方法,可以将NULLABLE设置为已经以NOT NULL形式存在的列:

您需要在数据类型中包含NULL(在我的情况下为decimal(13,4) NULL):

public void Configure(EntityTypeBuilder<TransferRequest> builder) { builder.Property(tr => tr.TotalAmountTTC).HasColumnType("decimal(13,4) NULL"); }

© www.soinside.com 2019 - 2024. All rights reserved.