2

Does anyone knows if it is possible to just rename a database table with Code First in Entity Framework 5?

I just have simple models and a database initializer, but since my database already contains data I've commented that initializer out. So, I don't want to drop and create a whole new database.

When I add new columns to such a model I use the Package Manager Console and run update-database. to update my database. Does this also work for renaming tables? Does the update-database command automatically knows what the old name was?

I don't have a lot of experience with CF yet and learning new stuff every day. Without CF it's 'easy' to just run an alter table command and refresh the dbml file... But with CF? I don't have a clue!

321X
  • 3,153
  • 2
  • 30
  • 42
  • If you use Table attribute it should work. – Maarten Oct 16 '12 at 21:15
  • Here is something similar. Hope this helps. http://stackoverflow.com/questions/5285781/entity-framework-code-first-change-table-column-collation – Jamie Oct 16 '12 at 21:16

2 Answers2

1

use

<Table("TableName")> _
Public Class ClassName
....
GilShalit
  • 6,175
  • 9
  • 47
  • 68
1

Obviously the update-database command knows what the old name was... So, in case of data loss warnings, you may choose to apply the -force option.

321X
  • 3,153
  • 2
  • 30
  • 42