EF database-first approach how to add new not null column to production table and manage at code level

asp.net-mvc ef-database-first entity-framework entity-framework-6

Question

My ASP.NET MVC 4 application uses Entity Framework 6 and a database-first approach. It is already in production environment, and now wants to add new column to the Deposit table and this column is not null. The production table already has a lot of data.

How should I manage this changes, in code-first approach, can anyone help me out? What should I do, I am new to Entity Framework.

1
0
8/30/2018 2:12:51 PM

Popular Answer

If you will continue to use the database-first approach you can do something like that:

1) run a script to migrate DB:

ALTER TABLE Deposit ADD <column_name> INT NULL
GO
UPDATE Deposit SET <a valid not null values for your column>
GO
ALTER TABLE Deposit  ALTER COLUMN <column_name> INT NOT NULL
GO

2) Since you are using the db-first approach you need update edmx model (.edmx file) which is already attached to db. If I remember correctly, you can do it from context menu in Solution Explorer.

0
8/30/2018 2:44:56 PM


Related Questions





Related

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