Tuesday, July 24, 2018

Question: How can I resolve the error upon using two different DbContexts?

I posted about this issue on stackoverflow

I've created a dbContext based on an existing Azure SQL Database using Entity Framework. I added this database to my app's services as follows:

public void ConfigureServices(IServiceCollection services) { //Identity Database Context services.AddDbContext<IdentityDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DataDb"), optionsBuilders => optionsBuilders.MigrationsAssembly("WebPortal")) ); services.AddIdentity<IdentityUser, IdentityRole>() .AddEntityFrameworkStores<IdentityDbContext>() .AddDefaultTokenProviders(); //Custom Database Context services.AddDbContext<CustomDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("CustomDb")) ); services.AddMvc(); } 

When I try to run this I get the following error message:

InvalidOperationException: The DbContextOptions passed to the IdentityDbContext constructor must be a DbContextOptions. When registering multiple DbContext types make sure that the constructor for each context type has a DbContextOptions parameter rather than a non-generic DbContextOptions parameter.

The constructor for my custom Context does have a parameter:

public CustomDbContext(DbContextOptions<WITSPeopleContext> options) : base(options) { } 

Why am I getting the error?

Question: How can I resolve the error upon using two different DbContexts? Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team