-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrations: Order columns of abstract base class properties last in CreateTable #11314
Comments
@TanvirArjel Can you be more specific about what is "wrong" with the order generated? For example, is it just that the primary key is not the first column? Or is it also that the unmapped base type should go at the end? If the latter, then what is the logic that determines this and would that also be true if it was a mapped base type? |
@ajcvickers Yes! Primary key should be the first column and the unmapped based type columns should go at the end.. |
@TanvirArjel Can you provide an explanation as to why the unmapped base type should go at the end and whether or not this should also be the case for a mapped base type? (I'm not saying you're wrong, I'm just trying to understand what the reasoning is behind this ordering.) |
Dear @ajcvickers , Thanks for your persistent reply. Does it make sense that the primary key of the table at column no. 5 or so other than the first column of the table? Look at the two orders of the columns in the question. Which makes sense? Which is more meaningful? Obviously not the first order..Hope,you will also be agree with me. In case of unmapped based type, yes! it also be more readable and rational that unmapped based type columns should go at the end of the table because normally in the common unmapped base type we put the columns which are common to the every table like CreatorName, CreationTime, ModifierName, ModificationTime etc. These columns at the beginning of the table does not make sense. Point to be noted that, In Entity Framework 6.2.0, Primary key of the table is always the first column and both unmapped and mapped based type goes at the end. This really makes sense! I know Entity Framework Core is a breaking change from Entity Framework but what's wrong to bring these already accustomed,well tested and more sensible behaviors from Entity Framework to Entity Framework Core? |
@TanvirArjel Thanks for the additional information. It will help us decide our course of action here. |
Triage decisions:
|
Dear @ajcvickers, Thanks a lot! for taking speedy action..That's why we love and rely on Microsoft :) |
Is there any workaround for this? |
I manually edited the files and changed the order; but it's a royal pain in the behind. |
I'm still manually edit the migration file, and as @tehZeno says, it's a royal pain in the behind :( |
This is wild. There are a multitude of issues that have been opened over the course of the last five years, closed for various reasons and ultimately hundreds, or possibly thousands, of hours wasted because no one has just fixed this issue. I was thinking about using EF Core, but I mean......... this is painful after the last 30 minutes of reading through these issues. |
@drewpayment I definitely agree to the number of hours wasted on this one issue, but I also understand that there are more important issues for the team to be focussed on, what we need is more people to upvote the priority of this issue. Atleast the issue remains open :) |
In any case for those of you that like me are manually ordering the migrations, have you found a way to order columns when adding a new column to an existing table? |
@Luis-Palacios No way! You have to do it manually. |
I managed ordering by customizing |
I tried it and it works, thanks and regards. |
can this be fixed already we are on version 3.1 of ef core already. I would also like to see the "index" attribute back. like ef 6 had. I wouldn't think it would be that hard to implement order by on attributes for migrations. |
Yes, the plan is to fix this in the next version of EF Core. Here is the issue for an index attribute: #4050. I'm not sure what you mean by order by on attributes for migrations, but please always feel free to submit a PR; all six team members are eager to help users fix their biggest pet peeves or implement small enhancements. |
Please fix this soon, it is pretty high on the list when sorting the issues by most comments. |
@bricelam FYI just in case it wasn't clear There are two attributes....
What we are wanting is the order they are specified in the model. We also want to be able to specify preference.... so giving a lower Order will make it appear closer to the start. Basically what EF6 is doing with the added ability to specify higher or lower index on abstract classes. This issue is more about the ordering than the Index, just sharing as you gave a link to the missing Index one, but the "bigger" issue is the order. Index can be specified using fluent notation.
the order
|
Nobody here has any expectations about unmapped types in the middle of a hierarchy, right? This is just about the case identified in the issue description? |
Also, if an owned type has an unmapped base type, it's properties should go next to the other owned type's properties still, right? |
Yes! but if anybody wants this then he/should be able to use |
This doesn't work with MySQL. Any thoughts?
|
Today, with Net 5.0 RC2 and Pomelo.EntityFrameworkCore.MySql: public partial class BaseEntity [Table("Tb_Geo_Zone")]
Sql autogenerated from Migration: CREATE TABLE Now it works!!!! |
I'm having the same issue in EF Core 6.0.3 on VS2022 with SQLServer DB |
Before the release of Entity Framework Core 2.1, Entity Framework Core team announced that,
but unfortunately, it is not working as expected in case of the following scenarios:
Entity Framework Core Migration is generating the Employee Table columns as the following order:
Actually It should have been:
Note that, Entity Framework 6.x Migration generates the columns as expected order even in case of inheritance.
The text was updated successfully, but these errors were encountered: