Reputation: 584
Using the wizard, I created a DbContext from an existing database and only selected one table to be pulled in. However now I need to add additional tables from that database to the Entity Model.
What is the easiest way to add more tables from an existing database to a context that I have already created and to also generate the respective models for those tables?
Upvotes: 2
Views: 4987
Reputation: 13777
If you want to add the tables manually to your DbContext, you can do so by adding properties of type DbSet to the DbContext. For ex:
public DbSet<CarColor> CarColors { get; set; }
Upvotes: 2
Reputation: 369
I think EntityFramework Reverse Poco Generator is what you're searching for. It's an extension for VS which allows to populate a TT file, then creating POCO entities for you.
It is downloadable here: EntityFramework Reverse Poco Generator
I've wrote a very brief guide you could refer to, in order to setupt the extension and use it for your means. Check it here: Introduction to EntityFramework Reverse POCO Generator for Visual Studio
Upvotes: 0
Reputation: 714
Easiest way is:
1) Open your .edmx database
2) Right click and choose "Update model from database..."
3) check the tables you want and click finish
4) EF will create all your entity classes for you
Upvotes: 4