Reputation: 33
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?
Upvotes: 1
Views: 2516
Reputation: 812
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.,
Upvotes: 2
Reputation: 1618
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.
Upvotes: 0
Reputation: 511
It depends on how you're initializing the database in your applications. EF performs a comparison on initialization of the DbContext and if the database schema is different than the model in your DbContext, it will produce an error by default. You can customize the behavior using different initialization strategies.
Upvotes: 0