0

I've read all the below questions (and more)


I want to know how IdentityDbContext adds its tables (AspNetUsers, AspNetUserLogins, etc.) to an existing database on the first application run.

I don't think they use any of these mechanisms to check if a table exists then apply a migration if not.

Is there any reference to the source code they use ?

Note:

I ask because I have multiple DbContexts in my application, and I want to (find a database-independent solution to) add only the db tables that the user will need at runtime.

Ahmad Ibrahim
  • 1,915
  • 2
  • 15
  • 32
  • It does use the same mechanisms (Models, DbSets, etc). They are in the base classes so you don't see the code. If you point to a blank database it will create the identity tables unless you have a null initializer. Adding migrations will also generate the tables. – Steve Greene Apr 26 '18 at 13:34
  • @SteveGreene I know they use Models, DbSets, etc. but what else do they do for adding their tables at runtime to an existing db ?.. When I use 2 normal DbContexts for the same db, the first one creates the database and the second one throws an exception complains that the db has been changed since the model created. – Ahmad Ibrahim Apr 26 '18 at 16:46
  • You could just use a single context that inherits from IdentityDbContext. If that is not possible, then set your initializers to null or MigrateDatabaseToLatestVersion and use migrations. – Steve Greene Apr 26 '18 at 20:30

0 Answers0