The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My work

  • My badges

  • Twitter Updates

  • My Flickr Stream

    20140508-Delphi-2007--Project-Options--Cannot-Edit-Application-Title-HelpFile-Icon-Theming

    20140430-Fiddler-Filter-Actions-Button-Run-Filterset-now

    20140424-Windows-7-free-disk-space

    More Photos
  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,322 other followers

Entity Framework: EF4 – update model from database ignores some changes

Posted by Jeroen Pluimers on 2011/09/13

Almost a year ago there was a post on the MSDN forums titled EF4 – update model from database ignores some changes.

These are the changes it ignores that I found so far:

  • Column renames
  • Column data type changes
  • Changed foreign key relations

Have you found others?

Do which EF versions are worse/better in this respect?

Note that the EF support in Visual Studio 2010 does not warn you if the the model is incompatible with your database.
You will get errors like this at run-time:

System.InvalidOperationException: The 'Size' property on 'ParentEntity' could not be set to a 'Int64' value. You must set this property to a non-null value of type 'Int32'.
   at System.Data.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal)
   at System.Data.Common.Internal.Materialization.Shaper.GetPropertyValueWithErrorHandling[TProperty](Int32 ordinal, String propertyName, String typeName)
   at lambda_method(Closure , Shaper )
   at System.Data.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly[TEntity](Func`2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet)
   at lambda_method(Closure , Shaper )
   at System.Data.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper)
   at System.Data.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext()

The workaround is simple but tedious:

  1. check all the errors, (so you need a thorough testing scheme in place)
  2. make a list of all the entities involved
  3. for each entity:
    1. note all the manual changes you did
    2. delete it from the model
    3. add it to the model
    4. re-apply the manual changes you did

–jeroen

2 Responses to “Entity Framework: EF4 – update model from database ignores some changes”

  1. bill bates said

    Same old problem. The code first fluent guys are messing up the database first. Why doesn’t Microsoft get the one way working correctly first before doing all the fluent Rad, go and fumble stuff? It looks like the regen of the entity model doesn’t work for ef-4.1. maybe they will get this act together for Juneau.

  2. Craig said

    I think you’ll find the SSDL is updated, but the CSDL isn’t. EF designer won’t change CSDL once it’s created. So you can manually update CSDL or redo the whole thing from scratch.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

Join 1,322 other followers

%d bloggers like this: