1

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)

  • Microsoft.AspNetCore.Identity.EntityFrameworkCore 5.0.6
  • Microsoft.EntityFrameworkCore.SqlServer 5.0.6
  • Microsoft.AspNetCore.Identity.UI 5.0.6
  • Microsoft.EntityFrameworkCore.Design 5.0.6
  • Microsoft.EntityFrameworkCore.Tools 5.0.6

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

  • keep ~Views\Shared_Layout.cshtml page

  • database context class specified as MvcMovie.Data.MvcMovieContext

  • no files overwritten

  • no user class specified

  • ok

  • process updates dependencies

  • builds solution until error

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.

3
  • 2
    The error is very clear. I imagine your DB context is public class MvcMovieContext : DbContext, where DbContext should be IdentityDbContext. I don't know if you'll experience any further errors, but that should address this particular error at least. Commented Jun 17, 2021 at 0:58
  • Any update about this case after you change your DbContext to IdentityDbContext as @MattU said? Commented Jun 17, 2021 at 6:00
  • Was unsure of the logic behind suggestion of changing MvcMovie base class from DbContext to IdentyDbContext. Just to be clear. I have a working solution with database connectivity. Trying to scaffold (renamed version of my original project folder) So only authorized users can use app. Don't get as far as introducing Identity code in the project. In meantime am doing it differently. Will review DbContext v IdentityDbContext within new code. Originally was trying to avoid repeating the entire original project. Looks like I will be doing this. Commented Jun 17, 2021 at 20:49

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.