3

I have been using EF Core Power Tools to reverse engineer an existing SQL database. We are now at the stage where we wanted to implement identity, I have setup the program.cs with this code:

builder.Services
       .AddIdentity<IdentityUser, IdentityRole>()
       .AddEntityFrameworkStores<ProjectDbContext>()
       .AddDefaultTokenProviders();

From what I read the ProjectDbContext should inherit from IdentityDbContext, not DbContext. Currently using EF Core Power Tools, it generates the DbContext as:

public partial class ProjectDbContext: DbContext

If I manually change that then the next time I build using Power Tools it will override it. Is there anyway to get that to work with IdentityDbContext? I've tried to add another partial class into the project:

public partial class ProjectDbContext: IdentityDbContext

but that causes the error:

Partial declarations of 'ProjectDbContext' must not specify different base classes

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Paritosh
  • 4,243
  • 7
  • 47
  • 80
  • You can set EF Core Powertools to only generate Models, when you synch. – Poul Bak Oct 04 '22 at 21:11
  • @PoulBak yes you are correct, but then I need to also add the DbSet<> manually for each table, I was hoping there was a way to keep generating it and have a way to use IdentityDbContext. – Paritosh Oct 04 '22 at 21:20
  • Actually a good feature, you want, I suggest you give it to the developer. – Poul Bak Oct 04 '22 at 21:22
  • Same situation here. Did you find a solution @Paritosh ? – Sylvain C. Oct 19 '22 at 14:11
  • 1
    @SylvainC. no, we ended up using a separate API for the Identity management portion so that one had it's own dbcontext which we used the IdentityDbContext. – Paritosh Oct 20 '22 at 12:19
  • Since you already have the ProjectDbContext and manually inherited from IdentityDbContext, try to refresh instead of edit on the efptcore.config.json file. – Aiyoub A. Feb 01 '23 at 21:47

0 Answers0