Dave
Dave

Reputation: 883

Adding Identity Scaffolding to ASP.NET Core MVC solution - getting error

Error:

DBContext type 'MvcMovieContext' is found but it does not inherit from Microsoft.ASPNetCore.Identity.EntityFrameworkCore.IdentityDBContext

The process I have followed using latest upgrade of Visual Studio 2019: latest relevant & other packages installed (showing Nuget Solution)

StartUp.cs

using Microsoft.EntityFrameworkCore;
using MvcMovie.Data;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;

public void ConfigureServices(IServiceCollection services)
{
    services.AddControllersWithViews();
    services.AddDbContext<MvcMovieContext>(options =>
                    options.UseSqlServer(Configuration.GetConnectionString("MvcMovieContext")));
}

After specifying Identity scaffolding template

I have reviewed similar issues here and github. The closest I (newbie) could find was UseSqlServer() method is missing from Microsoft.EntityFrameworkCore.SqlServer

I have looked through the build files of the working MvcMovie solution. I have updated dependencies. If someone could tell me how to troubleshoot why a DBContext type "does not inherit from Microsoft.ASPNetCore.Identity.EntityFrameworkCore.IdentityDBContext" then I would be much obliged.

Upvotes: 1

Views: 1461

Answers (2)

Lenny Woods
Lenny Woods

Reputation: 361

I had the same issue as normally I believe it is good practice to use a different DB context for your authentication , but I'm trying to do my business application all from an Azure free account and you only get 1 database so I need to also use my main DB for authentication. So inheriting from IdentityDbContext instead was what I had to do.

I looked into using Azure Active Directory for my authentication and conditional access but it looked way too involved for a small company of only 5 users. Actually, authentication was quite easy, but creating and implementing conditional access policies was what looked too involved for my simple needs.

Upvotes: 1

tlf
tlf

Reputation: 53

As @Matt U stated in the comments, changing DbContext to IdentityDbContext did the trick, along with including

using Microsoft.AspNetCore.Identity.EntityFrameworkCore;

within the context.cs file.

Upvotes: 1

Related Questions