开发者

Updating the database - MVC3, Entity framework 4.1

I have an application that uses a database with one table currently. I want to add another column to the table. According to this post(http://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part7-cs), there are 2 ways to modify the database: 1. Have EF drop and recreate the d开发者_开发技巧b or 2. Explicitly modify the db. Unfortunately, they go over the first method.

What is the correct / easiest way to do the second method if I have a table called Team?

The columns I have are TeamID, TeamAbbreviation, TeamCity, TeamName and TeamDisplayName. I want to add TeamSmallLogoUrl.


To do the second method, just go modify the DB and add your column. Then open the EDMX file in VS (double-click it in the Solution Explorer) and right-click on it when it opens up then choose "Update Model from Database" from the context menu. Click Finish. It'll pick up your added column.


Assuming you are using code-first (hence the EF-4.1 title):

If you are still in development phase and there are no important data in the database, use the Drop-Recreate method. (this is also the easiest way).

If you have some data in the database, just do this manually. The names of the properties and class should match/map directly unto your database schema. (if not mapped, EF will throw an error anyways)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜