等同于修改EFCore a迁移

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

目标

更改Migration.cs文件中的内容后,我想要类似Modify-Migration的内容。

已经尝试过

有一些我不小心使用Annotation,但现在我想删除该。我试图删除此行:.Annotation("SqlServer:ValueGenerationStrategy",SqlServerValueGenerationStrategy.IdentityColumn),from here

migrationBuilder.CreateTable(
    name: "LateFine",
    columns: table => new
    {
        StudentId = table.Column<int>(nullable: false)
        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
        FineAmount = table.Column<int>(nullable: false)
    },
    constraints: table =>
    {
        table.PrimaryKey("PK_LateFine", x => x.StudentId);
    });

并且对数据库进行此更改,以便表的SQL_Server设计如下所示:

Identity Specification: No

我已经知道,首先使用DatabaseGenerated(DatabaseGeneratedOption.None)不会产生该注释。

这是先前的代码

class LateFine
{
    [Key]
    public int StudentId { get; set; }
    public int FineAmount { get; set; }
}

这是我当前的修改

class LateFine
{
    [Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
    public int StudentId { get; set; }
    public int FineAmount { get; set; }
}

构建解决方案后,使用Update-Database命令,我已经得到了:No migrations were applied. The database is already up to date.

c# sql-server asp.net-core entity-framework-core ef-migrations
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.