1

I am writing an application using the VS2013 SPA template that includes Asp.NET Identity, WebAPI2, KnockoutJS and SqlServer Express 2012.

I started off using the IdentityUser class to handle my users and that worked just fine. I was able to add and login as a user with no problem. I then wanted to add custom information to the IdentityUser (there was an article I can no longer find).

As a result, I created an User class that inherited from IdentityUser as seen below.

public class User : IdentityUser
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

Then I updated all the references in the project from IdentityUser to User.

Now, whenever I try to login I get the following error:

The entity type User is not part of the model for the current context.

The thing is, I have a DBInitializer (public class ApplicationDBInitializer : DropCreateDatabaseAlways<ApplicationDBContext>) that always recreates the database and adds some test users and the tables are created and the users are added successfully.

On the off chance it matters, here is my cxn string: <add name="DefaultConnection" connectionString="Server=.\SQLEXPRESS;Database=ibcf;Trusted_Connection=True;" providerName="System.Data.SqlClient" />

and my DBContext

public class ApplicationDBContext : IdentityDbContext<User>
{
    public ApplicationDBContext()
        : base("DefaultConnection")
    {
    }
}

Why is this error happening?

drneel
  • 2,887
  • 5
  • 30
  • 48
  • Try checking this if it helps: http://stackoverflow.com/questions/20688922/the-entity-type-type-is-not-part-of-the-model-for-the-current-context – Allan S. Hansen Apr 05 '14 at 13:41
  • I tried that, but User is supposed to map to AspNetUsers and by doing that manually it causes a whole new crop of errors to pop up. – drneel Apr 05 '14 at 14:06
  • share your implementation of `OnModelCreating` from `ApplicationDBContext` class if you have one – dima Apr 05 '14 at 18:06

1 Answers1

0

The issue was that the Startup.Auth.cs continued to reference the default IdentityDbContext<User> DB context. After updating the class to reference my ApplicationDBContext the issue was resolved.

    static Startup()
    {
        ...

        UserManagerFactory = () => new UserManager<User>(new UserStore<User>(new ApplicationDBContext()));

        ...
    }
drneel
  • 2,887
  • 5
  • 30
  • 48