Click here to Skip to main content
14,265,797 members
Rate this:
Please Sign up or sign in to vote.
See more:
Quote:
My application is using EF6 Code First approach.
I have a poco class Employee with three properties Id, Name and Salary
and this class is derived from base class with properties created and modified date.

This class has been already migrated and have table in Db with 5 columbs namely, Id, Name, Salary, CreatedDate and Modified Date.

Now I have to add new properties Enum gender in the Employee class.
While doing so and updating the database new column Gender is created after modified date.
How do i create this new column after Salary ?


What I have tried:

I added Column Attribute and assign the order number in Employee calss as 0 for Id, 1 for Name, 2 for Salary and 3 for Gender 

and run add-migration and update-database command but it did not work.
Posted
Updated 4 days ago
Comments
MadMyche 4 days ago
   
Do you really need to alter the table? EF already has the columns mapped to your POCO properties; and you are most likely better just to leave it alone

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

The only way to change the order of the columns is to recreate the table. But it's really not worth it - the order of the columns in the table doesn't make any difference to performance, or to the behaviour of Entity Framework. The only time it would make any difference would be if you issued a SELECT * FROM ... query, which is a bad idea anyway.

Change Column Order in a Table - SQL Server | Microsoft Docs[^]
   
Comments
istudent 4 days ago
   
I agreed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100