如何对 EF Core 2.1 中的继承列进行排序?
How to sort inheritance columns ordering in EF Core 2.1?
我使用 EF Core 2.1 创建了 SQL 服务器数据库,
但是数据库列排序不会将继承列放在最后,
以下是我的实体代码:
public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
}
public class RssBlog : Blog
{
public string RssUrl { get; set; }
}
当前列的排序是:
1.RssUrl
2.BlodId
3.Url
我希望它在数据库中是这样的:
1.BlodId
2.Url
3.RssUrl
你能告诉我如何修复数据库列的排序吗?
谢谢!
我是英语初学者,如果我的单词或句子有问题,我很抱歉。
这是我在 EF Core 2.1 Preview 1 发布时提交的 Entity Framework Core 的未解决问题,但尚未修复(当前版本 2.1)。
2018 年 10 月 6 日更新
Entity framework核心团队计划在明年年初的 EF Core 3.0 版本中修复此问题。
详情如下:https://github.com/aspnet/EntityFrameworkCore/issues/11314
我在研究问题的解决方案时看到的一个技巧。
添加迁移时,您将获得以下脚手架迁移文件
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);
});
Table列排序结果如下;
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);
});
我们重新排序后,table 列顺序如下;
RssUrl
BlogId
Url
因此,在 ef 核心团队发布列顺序功能 (related issue) 之前,我们可以像上面那样对我们的列进行排序。
我使用 EF Core 2.1 创建了 SQL 服务器数据库, 但是数据库列排序不会将继承列放在最后, 以下是我的实体代码:
public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
}
public class RssBlog : Blog
{
public string RssUrl { get; set; }
}
当前列的排序是:
1.RssUrl
2.BlodId
3.Url
我希望它在数据库中是这样的:
1.BlodId
2.Url
3.RssUrl
你能告诉我如何修复数据库列的排序吗? 谢谢!
我是英语初学者,如果我的单词或句子有问题,我很抱歉。
这是我在 EF Core 2.1 Preview 1 发布时提交的 Entity Framework Core 的未解决问题,但尚未修复(当前版本 2.1)。
2018 年 10 月 6 日更新
Entity framework核心团队计划在明年年初的 EF Core 3.0 版本中修复此问题。
详情如下:https://github.com/aspnet/EntityFrameworkCore/issues/11314
我在研究问题的解决方案时看到的一个技巧。
添加迁移时,您将获得以下脚手架迁移文件
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);
});
Table列排序结果如下;
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);
});
我们重新排序后,table 列顺序如下;
RssUrl
BlogId
Url
因此,在 ef 核心团队发布列顺序功能 (related issue) 之前,我们可以像上面那样对我们的列进行排序。