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:
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.
No, there is no way to do that. You must run the wizard again, and generate the desired classes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With