entity-framework-core – 将Entity Framework中的SQL Server数据库字母列排序 – 首先更改为顺序

我需要先在代码中关闭字母顺序.

这是我的课程简化

public class Person
{
    [Key,Column("PersonId")]
    public int Id { get; set; }
    [MaxLength(50)]
    public string PersonName{ get; set; }
    public DateTime? JoinDate{ get; set; }
    public int? Gender{ get; set; }
}

当我运行命令来生成数据库

dnx ef migrations add InitialMigration
dnx ef  database update

当我在SQL Server 2012中以设计模式查看时,除主键之外的数据库列按字母顺序生成.

如何强制它按照类中出现的顺序创建列.

我看了一下github,只能找到this问题,但没有解释如何关闭它.

最佳答案 EF7迁移中没有这种行为的一流支持.您可以通过显式指定SQL迁移操作来解决此问题.

这意味着您不需要在迁移中使用“CreateTable”方法,而是需要显式编写SQL.

migrationBuilder.Sql("CREATE TABLE Person ...");
点赞