0

I'm extending the IdentityRole class in MVC with a Description property, the resulting table in the database is: Id, Description, Name. Is there a way to reorder columns using EF, to be Id, Name, Description?

here is the implementation of the derived class:

 public class MIdentityRole : IdentityRole<int, ApplicationUserRole>, IRole<int>
    {
        [Column("Description", Order = 2)]
        public string Description { get; set; }
        public MIdentityRole() { }

        public MIdentityRole(string name) : this()
        {
            Name = name;
        }
        public MIdentityRole(string name, string description) : this(name)
        {
            Description = description;
        }
    }

As shown, I tried to use the Column attribute, but it doesn't affect

Mohamed
  • 73
  • 1
  • 12
  • 1
    Reordering columns in SQL Server involves creating a copy of the table with the columns in the desired order (literally: copying all of the data over using `INSERT INTO ... SELECT FROM`) then `DROP TABLE` the original table and renaming the copy - it is not a cheap operation. Is there a reason you want to reorder the columns? Column order should not affect your programming code at all so it's largely unnecessary. – Dai Nov 26 '16 at 01:27
  • Why do you think the column order matters? Other than displaying it in SSMS, there is very little point. – DavidG Nov 26 '16 at 01:28
  • Check this: http://stackoverflow.com/a/1621/2026740 *You can not do this programatically (in a safe way that is) without creating a new table* – Daniel Corzo Nov 26 '16 at 01:29
  • Not sure if you use migrations, but you can change the order there while creating the table. Problem is that you will loose your data – Andrey Borisko Nov 26 '16 at 02:43

0 Answers0