Błąd przy dodawaniu kontrolera z widokami dla EF

0

Próbuje dodać do aplikacji kontroler z widokami CRUD.
Dostaję błąd "More than one DbContext named "WebApplication8Context" was found.

Jeśli dobrze rozumiem to mam tylko jeden taki twór. Dlatego nie rozumiem skąd błąd. Ale co kilka par oczu to nie jedne więc może naprowadzicie mnie na to co jest nie tak.
Kiedy robię migracje i update bazy danych program nie wyświetla błędu o większej ilości DbContext.

using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using WebApplication8.Areas.Identity.Data;
using WebApplication8.Models;

namespace WebApplication8.Data
{
    public class WebApplication8Context : IdentityDbContext<ApplicationUser>
    {
        public WebApplication8Context(DbContextOptions<WebApplication8Context> options)
            : base(options)
        {
        }


        public DbSet<Models.Tasks> Tasks { get; set; }
        public DbSet<TaskGroups> TaskGroups { get; set; }
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
            // Customize the ASP.NET Identity model and override the defaults if needed.
            // For example, you can rename the ASP.NET Identity table names and more.
            // Add your customizations after calling base.OnModelCreating(builder);

        }
    }
}

tutaj model, dla którego chce utworzyć widoki

namespace WebApplication8.Models
{
    public class Tasks
    {
        [Required]
        public int Id { get; set; }
        [Required]
        public DateTime CreatedAt { get; set; }
        public DateTime? EndedAt { get; set; }
        [Required]
        [Column(TypeName = "text")]
        public string CreatedBy { get; set; }
        [Required]
        [Column(TypeName = "text")]
        public string Title { get; set; }
        [Required]
        [Column(TypeName = "text")]
        public string Description { get; set; }
        [Required]
        public TaskGroups TaskGroup { get; set; }
        [Required]
        public string Status { get; set; }
        [Column(TypeName = "text")]
        public string WantedUser { get; set; }
    }
}
namespace WebApplication8
{
    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.AddControllersWithViews();
            services.AddRazorPages();

            services.AddDbContext<WebApplication8Context>(options =>
                    options.UseSqlServer(Configuration.GetConnectionString("WebApplication8ContextConnection")));
        }

        // 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.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });
        }
    }
}

plik json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "WebApplication8ContextConnection": "Server=SERV\\SQLEXPRESS;Database=Application;Trusted_Connection=True;MultipleActiveResultSets=true"
  }
}
0

Masz jest gdzieś ta klasę WebApplication8Context utworzona. Nie mogę mieć dwóch o tej samej nazwie.

0

@kzkzg: no właśnie nie mam. Wyszukuje po całej solucji nazwę i zwraca mi tylko wystąpienie w pliku, który wstawiłam, w startup i w connection stringu. No i w migracjach ale tam to wiadomo. Nigdzie indziej tej nazwy nie znajduje

0

Zobaczy może czy masz dwie klasy, które dziedziczą z IdentityDbContext.

0

@szydlak: Po IdentityDbContext tylko ta jedna. Druga dziedziczy po IdentityUser

0

To może jeszcze kwestia oczyszczenia solucji. Usunięcie katalogu .vs

0

Pokaż w konfiguracji serwisów co siedzi

1 użytkowników online, w tym zalogowanych: 0, gości: 1