Entity Framework v6.13 - Adding new column to table

c# entity-framework entity-framework-6 sql-server


I have several existing Windows console applications that use Entity Framework 6.13 to access a database table. I wish to add a new column to the database table. Will the existing console applications fail when the new column is added to the end of the table? I will not be changing any existing column names or attributes. I will not be changing the order of columns in the table. I plan to add the column to the end of the database table.

Will my existing production console applications using an Entity Framework model (that accessed the table without the new column) fail because of the change?

6/13/2016 10:46:06 PM

Accepted Answer

No, It will not fail your existing console applications even if you are adding New Column to your Existing Database Table. Because, Your Console Application's Entity Framework configuration will not aware of the Newly Added Column which was added to the Database side.

EF Fluent API always try to map your Domain Model with the Database Tables as per your configuration. If it mapped system will run with out any error. So, here you have not touched the Existing Database Table columns and you are only adding new columns. So, EF Fluent API can successfully map your Existing Database with Console application's domain model and console application can successfully run.

Note: I am Assuming that, newly added column does not have any constraints like NOT NULL, PRIMARY KEY etc.,

6/14/2016 10:44:33 AM

Popular Answer

Adding a column to the database will not cause any errors with Entity Framework models, assuming there are no constraints on the column. Any record created by EF will have the column set to null, and any updates made will not alter the value of the column.

Be aware that EF will not be aware of your column, and it may be lost if you later do a migration, or use dropCreate(on model changing / always) initialization strategy.

Also, order of the columns in the database does not impact entity framework.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow