Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add additional tables to an existing code first from database EF model?

When creating a new entity data model from an existing database using code first from database approach, one can directly specify which tables to include in the model. A subset (or all) tables can be selected in the Visual Studio wizard:

EF Data Model Wizard

In this example, Category and Product classes will be created along with the DbContext derived context class. If I later want to add additional tables to the same model, is there a simple way to add them, i.e. without having to manually create the classes myself?

E.g. initially, my DbContext class will contain:

public virtual DbSet<Category> Categories { get; set; }
public virtual DbSet<Product> Products { get; set; }

Now suppose I also want to include Employee table so that the DbContext class will be updated to:

public virtual DbSet<Category> Categories { get; set; }
public virtual DbSet<Product> Products { get; set; }
public virtual DbSet<Employee> Employees { get; set; }

VS context menus don't seem to provide this option, but maybe I'm missing something. Is there a way to bring back the wizard so I can select additional tables?

One solution is to have a separate empty project where you simply create a new model and then copy/paste new classes, but I'm curious if there's a faster way.

like image 412
w128 Avatar asked Sep 25 '14 11:09

w128


1 Answers

No, there is no way to do that. You must run the wizard again, and generate the desired classes.

like image 74
ErikEJ Avatar answered Sep 22 '22 04:09

ErikEJ