3

I am using entity framework DB first approach and wants to know how can i manage migrations in DB first approach. We're doing changes in database schema manually. Is there any way by which Entity Framework can apply the changes accordingly to the project.

Harish Bhatt
  • 584
  • 6
  • 15

2 Answers2

4

I guess I got confused between the code first with existing database and database first with model. What I understood is, after searching in different forums, Migrations are allowed only in code first approach. Code first assumes that you will never make any changes manually to the database. All the changes to the database will go through the code first migrations. This is true for code first with an existing database as well. If you are working with code first with existing database then it assumes that after connecting the the database for first time all the changes to the database will go through the code first migration instead of manually. When you are using Model instead of code first approach then any manual changes to the database can be migrated to the model by Update model from DataBase option. Which can be accessed by right clicking on the model.

I hope my understanding is correct but any modifications or corrections are welcome.

Tin Can
  • 2,540
  • 2
  • 29
  • 39
Harish Bhatt
  • 584
  • 6
  • 15
0
  1. You'll have to make the appropriate change manually
  2. You'll have to delete the model classes and generate them once again

EDIT:

I would recommend you to go through this: http://msdn.microsoft.com/en-us/data/jj206878.aspx

galdin
  • 12,411
  • 7
  • 56
  • 71
  • Yes i went through the msdn link and i have used the same way to start working on DB first approach. But wants to know is it not the risk to generate model classes again and again? – Harish Bhatt Nov 05 '13 at 07:11
  • @HarishBhatt you should be good with making the change manually in most cases. You'll need to generate the model class again only if there's major change in the database schema. You wont have any problem re-generating the model class though in most cases (in case you do, it'll be easily fixable depending on the design of your program) – galdin Nov 05 '13 at 12:11