locked
.Net Core: inheriting from IdentityDbContext RRS feed

  • Question

  • User-309523270 posted

    Hi,

    I have a solution target framework 2.2, which consists of 3 projects:

    DAL : contains the SchoolDbContext, the models and viewmodels
    BLL :  contains the Business Layer
    WebApp : supposedly MVC web app, except for the Model which is in the DAL layer.

    I'm using .Net Core 2.2, Oracle 11.

    I initially created the project with no authentication but am now trying to add Individual User Account Authentication to the working project.  I also created the project using Database-First approach.

    When I try to change

    public partial class SchoolDbContext : DbContext

    to

    public partial class SchoolDbContextIdentityDbContext

    I get the error :  'SchoolDbContext' does not contain a definition for 'SaveChanges' and no extension method 'SaveChanges' accepting a first argument of type 'SchoolDbContext' could be found (are you missing a using directive or an assembly reference?) 

    I already installed the following nuget for all the projects:

    install-package Microsoft.AspNet.Identity.Core -Version 2.2
    install-package Microsoft.AspNet.Identity.Owin -Version 2.2
    install-package Microsoft.AspNet.Identity.EntityFramework -Version 2.2
    Install-Package Microsoft.Extensions.Identity.Stores -Version 3.0

    When i try to clean and build the business layer, it gives the error, 'SchoolDbContext' does not contain a definition for 'SaveChanges' and no extension method 'SaveChanges' accepting a first argument of type 'ToolsDbContext' could be found (are you missing a using directive or an assembly reference?) ToolsOracle.Business.  This error did not exist in public partial class SchoolDbContext : DbContext 

    Moreover, when I try to add New Scaffold Item -> Identity in the WebApp, it cannot find the SchoolDbContext in the Business layer.  Then, It's generating the error "there-was-an-error-running-the-selected-code-generator".

    Also, could anyone direct me to a good resource for implementing Authentication in an multi-layered MVC project, Database First, ASP.Net Core, ?

    Thanks,

    tinac99

    Saturday, September 28, 2019 2:01 AM

All replies

  • User-2054057000 posted

    Hello @tinac99,

    If you do the all the steps of Identity correctly from start then you will not find these problem. Recheck all the steps and follow Setup & Configuration of Identity  management.

    You are also following Database-First approach approach which is not good today.  Programming has shifted to Code First Approach where you create C# classes for database object, then run migration commands on VS, and your database is created automatically on SQL Server (or MySQL, oracle, etc). 

    Thank you

    Monday, September 30, 2019 5:01 AM
  • User-309523270 posted

    Thanks, i'll try.

    Monday, September 30, 2019 3:50 PM