How to update model working with EF code first with 'Code First from Database'

.net c# ef-code-first entity-framework entity-framework-6


In a project EF 6.1 was used with an existing database using 'Code First From Database' approach as descibed in this article

Initially EF generated model classes, later some other classes were added to database and now I need to generate model classes for these new tables as well.

Please guide how I can do that without regenerating everything. Also instead of generating model classes for all tables, is there a way I can select tables to generate models for using same approach.

9/24/2014 7:29:38 PM

Accepted Answer

Go through the generation process, and during the generation process, it allows you to select tables. Select the newer ones only.

Instead of selecting all tables, expand the little triangle and select what you need. You also will have to select any dependent tables, or else the process will fail. If those dependent tables are already there, just delete the new code (unfortunately for them, there is no way to avoid generation).

enter image description here

There are some more tricks outlined in this here: Reverse engineering a subset of tables for Entity Framework

5/23/2017 11:46:07 AM

Popular Answer

One more option is just delete the auto generated classes from the project and once again generate them. While following this approach only thing we need to make sure that is, we should give the same name for the data model(class name which inherits from DbContext ) as the previous one.Data model name is highlighted in below snap. Data Model Name

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