I am trying to keep my applicaition and identity handling on their own seperate contexts, but I am running up agaisnt the "Cannot create a DbSet for 'CUserMasterLocal' because this type is not included in the model for the context." error message in doing so.
From my online research it appears that I need to have ApplicationDBContext inherit from IdentityDbContext rater than DBContext, but as stated, I want to have to have identity management in its own context. At least one Stackoverflow post tells me this is not allowed.
What I have tried:
This is my Identity context:
public class AppIdentityDbContext : IdentityDbContext<CUserMasterLocal, CRoleMasterLocal, string>
{
public AppIdentityDbContext(DbContextOptions<AppIdentityDbContext> options)
: base(options) { }
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
var x = builder.Entity<CUserMasterLocal>(config =>
{
config.ToTable("AspNetUsers");
});
builder.Entity<CRoleMasterLocal>(config =>
{
config.ToTable("RoleMaster");
});
}
public DbSet<CUserMasterLocal> UserMaster { get; set; }
public DbSet<CRoleMasterLocal> RoleMaster { get; set; }
}
In startup.cs I have
var identityConnectionString = this.Configuration["Data:VT_LocalIdentityData:ConnectionString"];
services.AddDbContext<AppIdentityDbContext>(options =>
options.UseSqlServer(identityConnectionString));
services.AddIdentity<CUserMasterLocal, CRoleMasterLocal>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
Within my controller, I have isolated the identity activity via a 'block'
using (var localIdContext = new AppIdentityDbContext(optionsBuilder.Options))
{
CUserMasterLocal userMaster = CreateUserMasterEntry(person, userDetails.GetUsername());
IdentityResult result = this.userManager.CreateAsync(userMaster, GeneratePassword(12)).Result;
}
For the avoidance of doubt CUserMasterLocal is not referenced in the class that sets up ApplicationDBContext, and I would like to keep it that way.
Here is the post that has me believe two contexts are not possible. Mean while
this post throws cold water over my intention to have my own user class.
Someone please say it ain't so, and guide me to a solution.