Это мой первый проект в ASP. NET MVC 5 и C# в целом. Я пытаюсь создать простое веб-приложение CRM.
Когда я пытаюсь установить роли в моем начальном методе, я получаю следующую ошибку после выполнения команды Update-Database
:
Тип сущности IdentityRole не является частью модели для текущего контекста.
Я много искал, но пока не нашел решения.
Конфигурация. cs
using System.Collections.Generic;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using simpleCRM.Models;
namespace simpleCRM.Migrations
{
using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
internal sealed class Configuration : DbMigrationsConfiguration<simpleCRM.DAL.crmContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
ContextKey = "simpleCRM.DAL.crmContext";
}
protected override void Seed(simpleCRM.DAL.crmContext context) //Takes our context as input
{
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
//Creating the admin role
if (!roleManager.RoleExists("Director"))
{
//Admin role
var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole("Director");
roleManager.Create(role);
}
context.SaveChanges();
}
}
crmContext.cs
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using simpleCRM.Models;
/*A class that coordinates the Entity Framework functionality for a given data model.
It derives from System.Data.Entity.DbContext class*/
namespace simpleCRM.DAL
{
public class crmContext: DbContext
{
public crmContext() : base("crmContext")//Passing the connection string to the constructor
{
}
public DbSet<Customer> Customers { get; set; }
public DbSet<Call> Calls { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingEntitySetNameConvention>();
}
}
}
Что может быть причиной ошибки?