Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
1.00/5 (1 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 13-Aug-19 4:33am
Comments
MadMyche 13-Aug-19 10:13am    
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

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[^]
 
Share this answer
 
Comments
istudent 13-Aug-19 11:35am    
I agreed.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900