This is my first ever project in ASP.NET MVC 5 and C# in general. I'm trying to make a simple CRM web app.
When I try to set roles in my seed method I get the following error after executing the Update-Database
command:
The entity type IdentityRole is not part of the model for the current context.
I've searched a lot but didn't find a solution yet.
Configuration.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>();
}
}
}
What might be the cause of the error?