skip to Main Content

See Image for the project structure.

I am using Clean Architecture web API in .NET 7. I need to employ the Database-First Approach because I am utilizing an existing database. However, I am creating the web API project from scratch. To do that, I also need to create ASP.NET Identity tables for user roles, and permissions in my application. So, do I need to manually create ASP.NET Identity tables as well, and scaffold tables like other tables? Or is there any way for Identity tables?

Previously, I was using the same structure but with a code-first approach. Now, I have to implement a database-first approach. Can you tell me what changes I am supposed to make?

2

Answers


  1. Database-first is exactly that. All tables/foreign keys, indexes etc are created outside of Entity Framework. Your C# code will not contain migrations, seed data, or anything else that would modify the database structure.

    Therefore, your database tables must be created by some other method. DbUp, SQL scripts,Database project, manually creating them, restoring from somewhere else, etc.

    Login or Signup to reply.
  2. 1.Use Db-first to restore context and models.
    2.Use code-first (Add-migration update-database) back to the database
    3.Change the generated context to inherit from IdentityDbContext
    4.Use code-first again to update the database with identity tables.

    The idea is how to update the database only with the "identity tables". When you use update-database, it will check the dbo._EFMigrationHistorytable

    In this table, if it a migration file has been update to database once, the migration file will be recorded in this table. So next time upgrade, the recorded migration file will be skipped.
    enter image description here
    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search