Khoa DANG TOAN
Khoa DANG TOAN

Reputation: 263

Auto generate entity model from database to current DbContext class

I am working on CodeFirst and have auto-generated the DbContext and Entities models for the first time.

Selected Code First from database.

It successfully generated Entity Models:

ACL_Action.cs, App.config, and ModelContext.cs.

But for awhile, the Database has had some new tables, and I have had to generate new C# Entity models. Currently, there is no way allow me to automatically generate a new Entity class for the existing DbContext.

Would you please advise me on it?

Upvotes: 0

Views: 1050

Answers (1)

Robin Zimmerman
Robin Zimmerman

Reputation: 689

You have three options (to my knowledge):

  1. Delete DbContext and existing models and regenerate from scratch. If you haven't made any changes to the default context or entities this is an easy approach.
  2. Generate a new model and copy and paste the DbSets and model configurations into your existing DbContext. Then you can just delete the newly generated context.
  3. EntityFramework Migrations - Once you have the database created you can make future updates to your code-first model and then apply them to your database rather than the other way around.

Upvotes: 0

Related Questions