[ACCEPTED]-The entity type ApplicationUser is not part of the model for the current context-asp.net-identity

Accepted answer
Score: 73

I was having this same problem. I’m doing 8 database first development with an EDMX 7 file.
If you are using the connection string 6 generated when adding the EDMX file in :base(“EDMXConnString”) you 5 will most likely have this problem.

I fixed 4 this by creating a standard connection string 3 that pointed to the database where the ASP.NET 2 Identity tables are.

<add name="MyConnString" connectionString="Data Source=server; Initial Catalog=db_name; User ID=user_id; Password=password; Connect Timeout=60;" providerName="System.Data.SqlClient" />

And then used that connection 1 string in :base, and it worked!

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("MyConnString")
    {
    }
}
Score: 43

for me it seems to miss a context instanciation:

UserManagerFactory = () => new UserManager<ApplicationUser>(new UserStore<ApplicationUser>());

should 1 be

UserManagerFactory = () => new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
Score: 9

My problem was I tried to use generated 6 ADO.NET connection string for both generated 5 and authentication context ApplicationDbContext. I fixed it 4 by using a separate connection string for 3 authentication. Also pay attention to the 2 provider - for authentication context it 1 has to be System.Data.SqlClient:

<add name="DefaultConnection" connectionString="Server=qadb.myserver.com;Database=mydb;User Id=myuser;Password=mypass;" providerName="System.Data.SqlClient" />
Score: 4

If you are using code first, check your 5 connection string to ensure providerName 4 is 'SqlClient' as in providerName="System.Data.SqlClient

If 3 you are using database first, check your 2 connection string to ensure providerName 1 is 'EntityClient' as in providerName="System.Data.EntityClient

Score: 2

Same problem to me, it solved by this code:

public ApplicationDbContext() : base("DefaultConnection", throwIfV1Schema: false)
{
    Database.Connection.ConnectionString = @"data source=...;initial catalog=...;user id=...;password=...;multipleactiveresultsets=True;application name=EntityFramework";
}

0

Score: 1

I also received this error message, but 8 the cause and solution were different. In 7 my case, I had introduced a new Id property 6 of type Guid in my ApplicationUser class. Perfectly 5 valid C# syntax, but it apparently created 4 massive confusion for the Identity or EntityFramework 3 core that relies on reflection to find stuff.

Removing 2 the new Id property in my ApplicationUser 1 class resolved this error.

Score: 1

I ran into this issue and it was an object 11 name conflict. The IdentityConfig.cs was 10 using ApplicationUser, but it was using 9 the auto-generated IdentityModels.ApplicationUser instead of my own context's 8 DataAccess.ApplicationUser. Made perfect sense once I found it. So, I 7 deleted the auto-generated IdentityModels.cs 6 from the base WebAPI template - not using 5 that anymore anyway - then I added the using 4 statement in IdentityConfig.cs to my own 3 DataAccess namespace and voila, proper mapping. If 2 you forget the template built a lot of this 1 for you, you'll run into the issue:

public class ApplicationUserManager : UserManager<ApplicationUser> // the name conflict
{
    public ApplicationUserManager(IUserStore<ApplicationUser> store)
        : base(store)
    {
    }
Score: 0

My issue was that I had created a new DbContext, but 2 it wasn't inheriting from IdentityDbContext.

An 1 easy fix...

public partial class GoldfishDbContext : IdentityDbContext<ApplicationUser>
{
 ....
}
Score: 0

I am sure not why this happens, my solution 18 works perfectly fine, tested everything 17 before I sleep. After 12 hours, I checked 16 it again and run and this was exactly the 15 same error. I tried almost all solutions 14 here in SO but none of them works.

I am implementing 13 a database approach here. Then suddenly 12 there was this

DefaultConnection

on my web.config 11 that Visual Studio generated when I first 10 created the solution. So I've used it instead 9 of the connection string that was generated 8 by my EDMX file and suddenly it works!

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("DefaultConnection", throwIfV1Schema: false)
    {
    }

    public static ApplicationDbContext Create()
    {
        return new ApplicationDbContext();
    }   
}

This 7 was my connection string that works:

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-System.WEB-20180718085411.mdf;Initial Catalog=aspnet-System.WEB-20180718085411;Integrated Security=True" providerName="System.Data.SqlClient" />

Originally 6 I am using this that was generated by my 5 EDMX file but suddenly the website doesn't 4 work although it works before. I didn't 3 change anything and all code was in TFS, so 2 I am 100% sure it works and I did a full 1 restore and get the latest version:

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-System.WEB-20180718085411.mdf;Initial Catalog=aspnet-System.WEB-20180718085411;Integrated Security=True" providerName="System.Data.SqlClient" />

More Related questions