【问题标题】:Data Migration Code First Table order is alphabetical数据迁移代码第一表顺序按字母顺序
【发布时间】:2016-10-15 04:12:44
【问题描述】:

该类具有以有意义的方式排序的属性,例如

        public int Id { get; set; }
        public string Name{ get; set; }
        public int CountryId { get; set; }
        public Country Country { get; set; }
        public Address {get; set;}
        public City {get; set;}
        [Timestamp]
        public byte[] RowStamp { get; set; }

运行数据迁移后,生成的表中的列按排序顺序排列。 生成的表有 Id 列,后跟 City 等。我喜欢保持课堂秩序 有什么方法可以避免在数据迁移时重新排序列?

【问题讨论】:

    标签: entity-framework data-migration


    【解决方案1】:

    您可以使用列属性(即 DataAnnotations)指定顺序,但我会警告您,维护起来可能会很麻烦(太麻烦了,IMO)。不过,它看起来是这样的:

    [Column("Id" , Order = 1)]
    public int Id { get; set; }
    

    查看Ordering Column Attributes in Entity Framework

    【讨论】:

    • 谢谢。我想要最后的审计列。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-14
    • 2019-04-05
    • 1970-01-01
    • 2020-11-26
    • 2010-12-22
    • 2023-02-10
    相关资源
    最近更新 更多