Search code examples
c#asp.net-coreasp.net-identity

Problems declaring other entities in the ApiAuthorizationDbContext<TUser> Class


I created a project using the .NET Core react + individual user authentication template. I am trying to declare other entities inside ApiAuthorizationDbContext<TUser> class but they somehow don't seem to appear in the database.

public class ApplicationDbContext : ApiAuthorizationDbContext<ApplicationUser>
    {
        public ApplicationDbContext(
            DbContextOptions options,
            IOptions<OperationalStoreOptions> operationalStoreOptions) : base(options, operationalStoreOptions)
        {
        }

        public Microsoft.EntityFrameworkCore.DbSet<Student> Students { get; set; }
}

I also have to prefixate them like this public Microsoft.EntityFrameworkCore.DbSet<Student> Students { get; set; }, otherwise I get this error 'DbSet<>' is an ambiguous reference between 'System.Data.Entity.DbSet<TEntity>' and 'Microsoft.EntityFrameworkCore.DbSet<TEntity>'.


Solution

  • Take a look on this documentation. In short, you should run migrations like this -

    1. install .net cli tools

    2. open cmd and "cd" to your .csproj

    3. create migration -

      dotnet ef migrations add InitialCreate

    4. update db with this command -

      dotnet ef database update