Column ordering
See original GitHub issueOutcome from much discussion on this topic…
In EF6 we tried having column order match the order of properties in the class. The issue is that reflection can return a different order on different architectures. Although the order of properties in the model does not theoretically matter… it actually created a lot of very difficult to debug issues on EF6 where the order had a subtle effect on conventions, model diffing, etc. We managed to fix some of them (after many releases) but there are still some issues we have never really fixed. For that reason, metadata is stored in a deterministic (alphabetical) order in metadata in EF7.
In EF6, we also had a column ordering API, but this only impacts the initial create of the table. If you later change the order, migrations does not handle this (it would require a table rebuild). Also, if you add new columns, they are always appended to the table (since anything else also requires a table rebuild).
We could, however, store an ordering hint as an annotation on the model (based on the reflection order). This would only affect the order that migrations writes the columns in a create table call. That way it doesn’t matter if it changes when you run your app on different platforms, since it’s just an annotation that is ignored for the most part. If we wanted to, we could also flow an order that was specified in [Column]
annotations into the hint field.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:8
- Comments:103 (33 by maintainers)
Top GitHub Comments
@vseyedan There is no plan to change this in any of the currently scheduled releases. The correct thing to do it you don’t like the column order is to edit the generated migration file and move the order around as desired.
There are times you need to write code at the database level and column order can become more important (inserting into a table without full column specs in a trigger for example). On a wide table, it can save time and since columns in sql databases don’t change order once written easily, is usually fairly safe.
In addition, I prefer to look at the model and data in the same column order 99% of the time so I am not hunting for information visually (example comparing query output debugging a query versus framework output). Maybe it’s a little OCD on my part as well as the consistency just “feels right”.
That or worst case obsolete the currently non-implemented .HasColumnOrder attribute so people know it is incomplete at least. 😃
Christine
From: Erik Ejlskov Jensen [mailto:notifications@github.com] Sent: Sunday, August 9, 2015 2:09 PM To: aspnet/EntityFramework EntityFramework@noreply.github.com Cc: Christine Boersen christine@daisytec.com Subject: Re: [EntityFramework] Migrations: Need column order annotation/API. (#2272)
@ChristineBoersen https://github.com/ChristineBoersen Why do you need to manage the colum order?
— Reply to this email directly or view it on GitHub https://github.com/aspnet/EntityFramework/issues/2272#issuecomment-129222648 . https://github.com/notifications/beacon/ANCv3frvA8bNvpsgfDiBF20GHBH12nS9ks5ol47YgaJpZM4Eqf6c.gif