До сих пор мой ApplicationDbContext унаследовал от DbContext и работал нормально.
Теперь я хочу, чтобы мой ApllicationDbContext наследовал IdentityDbContext вместо DbContext, но я получите следующие ошибки
Снимок экрана с ошибками.
Я установил необходимые пакеты NuGet (Microsoft.AspNetCore.Identity.EntityFrameworkCore и Microsoft.AspNetCore.Identity.UI)
Это мой ApplicationDbContext.cs
Код: Выделить всё
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.EntityFrameworkCore;
using RockyWebsite.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace RockyWebsite.Data
{
public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext(DbContextOptions options) : base(options)
{
}
public DbSet Category { get; set; }
public DbSet ApplicationType { get; set; }
public DbSet
Product { get; set; }
}
}
Код: Выделить всё
using Microsoft.Extensions.Hosting;
using RockyWebsite.Data;
namespace RockyWebsite
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext(options => options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity()
.AddEntityFrameworkStores();
services.AddControllersWithViews();
services.AddHttpContextAccessor();
services.AddSession(Options=> {
Options.IdleTimeout = System.TimeSpan.FromMinutes(10);
Options.Cookie.HttpOnly = true;
Options.Cookie.IsEssential = true;
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseSession();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/711 ... -dbcontext
Мобильная версия