3

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?

1
  • Open your EDMX file. Then right click in the diagram and select Update Model From Database. Next select the tables you would like to add. Commented Dec 5, 2016 at 19:29

3 Answers 3

4

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

Sign up to request clarification or add additional context in comments.

Comments

2

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; }

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.