Entity-framework – How to update only one table for model from database with Entity Framework

entity-frameworkentity-framework-4entity-framework-4.1entity-framework-5

I have a model generated from db with Entity Framework. When I have any change in database, I update model from database to get the change in model. But this update is applied to all entities (tables) included in model.

Now I add a new column in a table Tab1. I don't want to update model from database as some other changes that I don't want to include in model. I can add the new property in model for entity Tab1 manually. then it caused mapping error.

So I need to update Model.Store for the table to include the new column. It means I want to update model only for Tab1.

How can I do this?

Best Answer

The EDMX file is an XML file that is a combination of 3 different parts that make up the whole thing. If you right-click on your EDMX file and choose "Open with... XML Editor" you'll see the 3 different sections:

  • <edmx:ConceptualModels>
  • <edmx:StorageModels>
  • <edmx:Mappings>

These sections can be edited manually, at your own risk! :-)
That way you can modify only what you need to.

Note that it's also possible to generate CSDL, SSDL & MSL files rather than having them embedded in the binary file, by changing the "Meta Artifact Processing" property of your model to "Copy to Output Directory".

If you don't want to do this manually, there's the Huagati DBML/EDMX tool, it is free and you can download it from huagati official site or from visual studio gallery, which is a Visual Studio plugin that allows you to select what changes need to be done.