Reorder columns with EF 4.3 Code-First Migrations

Reading both walkthroughs here:

http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-code-based-migrations-walkthrough.aspx

http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspx

I couldn't find a way to specify the order of the columns in the SQL data table. Looks like the last added property is always mapped to the last column.

Example:

public class SampleData {
    public int Id { get; set; }
    public string Data2 { get; set; }
    public string Data3 { get; set; }
}

Will create a table with the column order:

Id | Data2 | Data3

Updating the class like:

public class SampleData {
    public int Id { get; set; }
    public string Data1 { get; set; }
    public string Data2 { get; set; }
    public string Data3 { get; set; }
}

Then running update will update the table into:

Id | Data2 | Data3 | Data1

Anyone knows if there's a way to specify the column order when using migrations?

Answers


There is no way except creating new table and moving all data from the old table to new one. The order of columns in the database is not important - you have your application and UI to order columns as you need.


Need Your Help

C only read from stdin if the desired input exists

c stdin scanf getline

I'm working on a C program where I want to user to type the following format into stdin:

Rails 3: Migrating a model to MongoDB

ruby-on-rails ruby mongodb

I have a few models in my existing Rails 3 app that are completely non-relational to the other models in the application's ecosystem. The underlying data is incredibly large and it would benefit in...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.