我在研究问题的解决方案时看到的一个技巧。
添加迁移时,您将获得以下脚手架迁移文件
migrationBuilder.CreateTable(
name: "RssBlog",
columns: table => new
{
BlogId = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
Url = table.Column<string>(nullable: true),
RssUrl = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_RssBlog", x => x.BlogId);
});
表列排序结果如下;
BlogId
Url
RssUrl
您可以重新排序脚手架迁移文件中的列;
migrationBuilder.CreateTable(
name: "RssBlog",
columns: table => new
{
RssUrl = table.Column<string>(nullable: true),
BlogId = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
Url = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_RssBlog", x => x.BlogId);
});
重新排序后,表格列的顺序如下;
RssUrl
BlogId
Url
因此,在 ef 核心团队发布列顺序功能(相关问题)之前,我们可以像上面一样对我们的列进行排序。
详细的博文