I'm currently working on a project that is utilizing EF Code-First. Now, we've already made 3 tables in our database, and using migrations are able to update them just fine. Now, we've decided that we actually need another table in our database. I've created the class and the context for it. I assumed I could use a migration for this to update the database; however, when I created the migration, the file was completely empty. This particular table is not associated with any prexisting tables. How can I go about adding new tables like this?
You need to create a property in your DBContext and add mappings.
public DBSet<MyTable> MyTables {get;set;}
And you should have a mapping:
modelBuilder.Entity<MyTable>.HasKey(mt => mt.Id);
//...everything else...
When you run add-migration it should generate code for you/
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