I just finished creating a new website using code first - MVC 4. The user asks now for a new field in a table. I couldn't find an easy way to implement this. I changed the model to include the new field but I get the an error.
Any idea on how I can do this without droping and recreating the table ?
This is exactly what I did, I made changes to the table, changes to my model classes, but no EDMX file, I'm using SQL Server 2008 not the Express version.
mpop
0 Points
3 Posts
MVC Code First
Nov 23, 2012 01:21 AM|LINK
I just finished creating a new website using code first - MVC 4. The user asks now for a new field in a table. I couldn't find an easy way to implement this. I changed the model to include the new field but I get the an error.
Any idea on how I can do this without droping and recreating the table ?
Marc
anuj_koundal
Contributor
2088 Points
496 Posts
Re: MVC Code First
Nov 23, 2012 06:00 AM|LINK
Some nice articles for your problem
Regards
Anuj Koundal
ignatandrei
All-Star
134983 Points
21638 Posts
Moderator
MVP
Re: MVC Code First
Nov 23, 2012 06:41 AM|LINK
alter table add column
or search for
ef code migration
ashoksudani
Participant
1043 Points
213 Posts
Re: MVC Code First
Nov 23, 2012 10:44 AM|LINK
If you need to Add new Column in Table so do Following Stap.
Add Column in Table
Update your Edmx File in Visual Studio. open Edmx and right Click and Click on "Update Model From DataBase" so it is Add one Column in Your Edmx.
now you need to Change You Code as per Requirment. for inser update and Select.
mpop
0 Points
3 Posts
Re: MVC Code First
Nov 23, 2012 01:58 PM|LINK
Thank you for your answer,
This is exactly what I did, I made changes to the table, changes to my model classes, but no EDMX file, I'm using SQL Server 2008 not the Express version.
Marc
mpop
0 Points
3 Posts
Re: MVC Code First
Nov 23, 2012 02:56 PM|LINK
At the end I did it thru "Package Manager Console" but I'm still looking if there is another way to simple change the model class when DB is changing.
Thank you,
Marc