Updating models from database in Entity Framework 6.0

ado.net-entity-data-model c# entity-framework entity-framework-6 sql-server-2008


In Visual Studio 2013, I'm creating a Web API Service and have incorporated an ADO.NET Entity Data Model to my project (Database First).

In my edmx diagram, every table I've included has been successfully constructed.

Then I made some adjustments, removing one column and adding two new columns to the original database. Therefore, when I attempt to update my model from the database, two new columns are added, but my model still has the removed column.

Error 11009: Property 'Image' is not mapped.

Where Image is the name of the database column that was deleted.

Can this property be manually removed from the model? Or is there a more hygienic and secure approach?

2/3/2015 8:32:08 PM

Accepted Answer

Sure, as others have stated, changing the approach could be a better way to work with EF and DB, but starting from the fact that you need Database First, I think working with Database First Model has its benefits, one of which is the EDMX is taken as is, meaning as a generated piece of code, you can refresh, destroy, and recreate that every time you need or want without losing any modification.

You can remove a property, but the model and database are not transparently in sync because, as I previously stated, the nature of produced code guarantees that every modification you make to the EDMX will be lost.

I believe the greatest strategy for doing that is

  1. Restructure the database.
  2. Update the EDMX, then delete it and then recreate it if the update "fails," indicating the changes are not reflected.

Even though this method could be overly straightforward, it doesn't violate the database's inherent integrity.

Just a reminder: Using partial classes to add items to the DbContext and the entities involved to add features and behaviors can help when working with the database first.

3/25/2014 8:34:47 AM

Related Questions


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