locked
EF Core -> Split one Model into two RRS feed

  • Question

  • User-1188570427 posted

    Hello,

    I have an API that has one schema that references dbo. I need to make 2 different APIs that will be two new schemas now and remove all tables from dbo.

    I also need to remove about 5 tables/a couple of fields 100% from the model and database forever.

    I have one ContextModel.cs and one ContextModelSnapshot.

    I need to move all the tables into dbo into 2 new schemas.

    The two new APIs/Schemas are: CORE API and MAIN API.

    The Entities/Classes and Entities/Models are the same in both APIs.

    I now need to remove X tables from CORE API and X tables from MAIN API.

    Do I just work on one (CORE) API, delete the necessary items that need to be removed, and then run add-migration to get what truly needs to be deleted on the first API -> meaning keep what is in the UP()?

    Then delete all the tables that are in the other API (MAIN) from the first API (CORE), run add-migration and just remove all the items from the Up() / Down() since those will still need to be in the other API/Database Schema?

    Then do the same thing on the 2nd API (MAIN) -> remove all the tables that are in the 1st API (CORE), run add-migration, then delete everything from Up() / Down(). 

    Then make a migration on both APIs that will move the tables from dbo to their necessary schemas (CORE/MAIN)?

    Friday, January 24, 2020 4:28 AM

All replies

  • User1120430333 posted

    All this would be simply a whole lot simpler by using SSMS to administer the database or databases, and then you can use EF Core for  existing database approach and be done with it. 

    All this migration stuff is an unnecessary complication, IMO.

    Friday, January 24, 2020 8:43 PM
  • User-1188570427 posted

    All this would be simply a whole lot simpler by using SSMS to administer the database or databases, and then you can use EF Core for  existing database approach and be done with it. 

    All this migration stuff is an unnecessary complication, IMO.

    Well, so you are saying I should re do the models after the databases are changed? Meaning re-baseline the model etc?

    The one thing I'm worried about is when I run add-migration, it will change something that shouldn't be changed etc. 

    Saturday, January 25, 2020 6:14 AM
  • User1120430333 posted

    Well, so you are saying I should re do the models after the databases are changed? Meaning re-baseline the model etc?

    I am saying let EF Scaffold the Dbcontext from the existing DB schema that has been modified and create the model.

    The one thing I'm worried about is when I run add-migration, it will change something that shouldn't be changed etc.

    You could use DBA tools traditionally. I am not a fan of an ORM doing DBA stuff. 

    Saturday, January 25, 2020 6:47 AM