In Entity Framework, update the database schema.

.net entity-framework schema

Question

I installed VS SP1 and played around with Entity Framework.

I created a schema from an existing database and tried some basic operations.

Most of it went well, except the database schema update.

I changed the database in every basic way:

  • added a new table
  • deleted a table
  • added a new column to an existing table
  • deleted a column from an existing table
  • changed the type of an existing column

The first three went well, but the type change and the column deletion did not followed the database changes.

Is there any way to make is work from the designer? Or is it not supported at the moment? I didn't find any related material yet, but still searching.

1
8
8/25/2008 5:05:06 AM

Accepted Answer

I would guess that possibly those don't happen because they would break the build for existing code, but that's just a guess on my part.

Here's my logic:

First, EF is supposed to be more than 1:1 table mapping, so it's quite possible that just because you are deleting a column from table A doesn't mean that for that entity, there shouldn't be a property Description. You might just map that property to another table.

Second, changing a type could just break builds. that's the only rationale there.

6
8/15/2008 4:18:22 PM

Popular Answer

I've found that, in general, there are still quite a few bugs with the 'Update Model from Database' functionality.

Keys are the killer for me - I've yet to have any modification I make to a foreign-key relationship or to add a Primary Key to a table and have the updater work correctly (in that it will give a compile error on the generated code) - but to solve the problem it's a simple matter of deleting the model and re-importing (only takes a minute) - this is less than ideal obviously, but I've never had a failure from a 'fresh' import.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow