0

I need to add a new column / property to my database and my model without EF Code First dropping my database.

Is there a way to manually map a column to property so EF would not drop my database?

Update:

Got it to work by following this post on SO.
https://stackoverflow.com/questions/6049135/manually-editing-database-in-code-first-entity-framework

Basically you just need to:

  1. Manually add the column to your database
  2. Manually add the property to your model
  3. Disable any database initializer in your DataContext
Community
  • 1
  • 1
Drew
  • 888
  • 7
  • 12

1 Answers1

0

As long you're using anything beyond EF 4.3, you would use Migrations to do so. You can't do it manually because EF relies on the model that is stored in order to best do the mapping to SQL. When you make a change it refreshes the model. Any attempt to add something without changing the model will result in an exception.

Corey Adler
  • 15,897
  • 18
  • 66
  • 80