C# 如何在EF Core 2.1中对继承列排序?
我使用EF Core 2.1创建SQL Server数据库, 但是数据库列排序不会将继承列放在最后, 以下是我的实体代码:C# 如何在EF Core 2.1中对继承列排序?,c#,sql-server,ef-core-2.1,C#,Sql Server,Ef Core 2.1,我使用EF Core 2.1创建SQL Server数据库, 但是数据库列排序不会将继承列放在最后, 以下是我的实体代码: 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.Bl
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发布时提交的实体框架Core的开放版本,但尚未修复(当前版本2.1) 更新日期:2018年10月6日 实体框架核心团队计划在明年初的EF core 3.0版本中解决这个问题
以下是详细信息:我在研究问题解决方案时看到的技巧 添加迁移时,您将获得以下搭建的迁移文件
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);
});
您可以对脚手架移植文件中的列重新排序
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);
});
因此,在ef核心团队发布列顺序功能()之前,我们可以像上面那样对列进行排序
这是EF Core的一个公开问题,您可以在@Caldazar上看到,谢谢!!!感谢您提供了一个好的解决方案。尽管这是一个很好的解决方案,但仍然很麻烦,因为如果我有这么多实体,我需要亲自调整它们。
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