0

After creating a new table using code behind in C#, I want to update my model from the database by my C# code not with the wizard (Database first). Is that possible?

Twenty
  • 5,234
  • 4
  • 32
  • 67
  • I think it is, but if you started with doing code behind; you should stick with code behind. This way it is the model that drives the DB, instead of a weird hybrid system. – SomeStudent Feb 12 '20 at 17:51
  • That sounds more like code first if you are changing the code behind. You will need to use either [migrations](https://learn.microsoft.com/en-us/ef/ef6/modeling/code-first/migrations/) or an [initializer](https://blog.oneunicorn.com/2013/05/28/database-initializer-and-migrations-seed-methods/) like `DropCreateDatabaseIfModelChanges` that updates your database when the model changes. The latter can be used while you are in early development stages. Then switch to migrations when you don't want unseeded data to get wiped. – Steve Greene Feb 12 '20 at 18:18
  • i don't want to use code first, i need any way to update model after table inserted in database but not wizard. – MOHAMMED BAZBAZAT Feb 13 '20 at 06:04
  • OK, your question says you created the table in code. You want this: https://stackoverflow.com/questions/2947511/entity-framework-how-do-you-refresh-the-model-when-the-db-changes – Steve Greene Feb 13 '20 at 21:06
  • @SteveGreene i need these steps : 1-Select all the tables and view-s in the EDMX designer. 2-Delete them. 3-Then, update model from database **not wizard, i need to do it by code.** – MOHAMMED BAZBAZAT Feb 16 '20 at 14:13

0 Answers0