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

the entity type is not part of the model for the current context
the entity type is not part of the model for the current context updateentitysetmappingsfortype
the entity type applicationuser is not part of the model for the current context. db first
the entity type identityrole is not part of the model for the current context.
keyword not supported: 'metadata'.
applicationuser type

I am seeing the same issue as this question, but the scenario presented there doesnt seem to apply so I think I have a different issue. In fact, I'm seeing several questions on SO that are similar, each with different causes and solutions, so I think this error must be caused from a high level. That said...

I have an EF code-first database model and I'm trying to use IdentityUser to extend a standard registration for my MVC 5 site.

I have my extended UserModel:

namespace MyMvcSite.Models {
    public class UserModel :IdentityUser {
        public string BillingId { get; set; }
        public virtual ICollection<DatabaseModel> Databases { get; set; }
}

And my context:

using MyMvcSite.Models;
namespace MyMvcSite.Web {
    public class AuthContext : IdentityDbContext<UserModel> {
        public AuthContext() : base("AuthContext") {

        }
    }
}

Now, when I execute the code to register a user:

public async Task<IdentityResult> RegisterUser(UserModel user) {
    user.Email = user.UserName;
    var result = await _userManager.CreateAsync(user);

    return result;
}

I get the error: The entity type IdentityUser is not part of the model for the current context. I can't figure out what this error means, because it looks - to me - like I have everything correct. Can anyone tell what might be going wrong???

I know my connectionString AuthContext is correct because I have used it previously.

When you are using a custom user class with ASP.NET Identity, you have to make sure that you explicitly specify the custom user class type <T> to both the UserManager and the UserStore on instantiation.

private UserManager<UserModel> _userManager;

public AccountController()
{
    AuthContext _ctx = new AuthContext();

    UserStore<UserModel> userStore = new UserStore<UserModel>(_ctx);
    _userManager = new UserManager<UserModel>(userStore);     
}

or in shorter form (like your reply comment):

private UserManager<UserModel> _userManager;

public AccountController()
{
    AuthContext _ctx = new AuthContext();    
    _userManager = new UserManager<UserModel>(new UserStore<UserModel>(_ctx));     
}

If the type is allowed to defaulted to IdentityUser when you want to use a custom class you will experience the error you reported.

The entity type ApplicationUser is not part of the model for the , for me it seems to miss a context instanciation: UserManagerFactory = () => new UserManager<ApplicationUser>(new UserStore<ApplicationUser>());. The IdentityUser entity type is not part of the model for the current context I am seeing the same issue as this question, but the scenario presented there doesnt seem to apply so I think I have a different issue. In fact, I'm seeing several questions on SO that are similar, each with different causes and solutions, so I think

I was having this same problem, and I recall having a similar problem working with SimpleMembership in MVC4.

I’m doing database first development, so I have an EDMX file. Turns out, ASP.NET Identity does not like the connection string that is created when you generate your .edmx model file. If you are using a. EDM connection string in :base("EDMConnString") you will most likely have this problem.

I fixed this by creating a standard connection string that pointed to the database where the ASP.NET Identity tables are (in my case the same database), used that connection string in :base, and it worked.

Something like this

<add name="IdentityConnection" connectionString="data source=THEJUS\SQLSERVER2014;initial catalog=IdentitySample;integrated security=True;MultipleActiveResultSets=True;App=IdentitySample.Admin" providerName="System.Data.SqlClient" />

[SOLVED], for me it seems to miss a context instanciation: UserManagerFactory = () => new UserManager<ApplicationUser>(new� The entity type ApplicationUser is not part of the model for the current context Asp.Net MVC Try using IdentityUser instead of ApplicationUser,will Solve the

I got this error when I introduced DI to my project. Using AutoFac and Identity I had to add the following: builder.RegisterType<ApplicationDbContext>().As<DbContext>().InstancePerLifetimeScope();

Without this, when AutoFac was creating my UserStore instance, it was using the default UserStore() ctor which creates a new IdentityDbContext, not my ApplicationDbContext.

With this line, UserStore(DbContext context) ctor gets called, with my ApplicationDbContext.

ApplicationUser is not part of the model for the context, entity type ApplicationUser is not part of the model for the current context. Here is db context class;. public class ApplicationUser : IdentityUser� The entity type ApplicationUser is not part of the model for the current context. This exception is raised if you go to the login screen and try to log in. It occurs if you have a DbContext class that inherit directly to DbContext and not of IdentityDbContext. Your database context must be aware of Identity tables.

Here is some step i figured out while resolving this issue

  1. First Check your database for Table of ASP.Net Identity
  2. Create these table on your database if not exist you can also apply migration
  3. Check the below image and verify your code

Register Action

IdentityDbContext Class

Error on Customize of Identity- The entity type ApplicationUser is not , "The entity type ApplicationUser is not part of the model for the current context." What i did till now as public class ApplicationUser : IdentityUser� The entity type ApplicationUser is not part of the model for the current context. Line 76: // This doesn't count login failures towards account lockout Line 77: // To

c The entity type IdentityUser is not part of the model for the current , c The entity type IdentityUser is not part of the model for the current context? ApplicationDbContext UserStore(DbContext context) builder. The entity type ApplicationUser is not part of the model for the current context 1 Owin OAuth provider “The entity type IdentityUser is not part of the model for the current context”

The entity type applicationuser is not part of the model for the current , Solution : I was facing the same problem. I was doing database first development with my EDMX file. If you are also using your connection� The CreateUserAsync-method gives the following error: The entity type ApplicationUser is not part of the model for the current context. Now my questions: Am I doing this the 'mvc'-way? I feel this is a lot of work for something that in my opinion is trivial. If not, is there a better way to achieve this?

The entity type ApplicationUser is not part of the model for - html, The entity type ApplicationUser is not part of the model for the current context. the Roles property of the IdentityUser / ApplicationUser object is null or empty� "The entity type IdentityRole is not part of the model for the current context." I'm fairly sure I've done this, but i can't seem to figure out why, i've debugged and can't determine how I've messed this up. Every time i try to log in, i get this in the stack.

Comments
  • How do you instantiate your _userManager and its context? This seems like it might help: stackoverflow.com/questions/23893710/…
  • My _userManager was initialized to: _userManager = new UserManager<IdentityUser>(new UserStore<IdentityUser>(_ctx));. I changed it to _userManager = new UserManager<UserModel>(new UserStore<UserModel>(_ctx));, which solved it! Post this as an answer and I'll accept. Thanks for pointing me in the right direction!
  • This did it! Thanks!
  • Thanks! Perfecto!
  • Yes. That solved my problem. There are 2 connection strings needed. One for Identity stuff and one for EF. If you look in Web.Config you will see a Default Connection and then one EF makes when you configure it during installing it. You can easily build a dummy MVC5 and add EF to see them and use them if your database is the same. My problem was caused by an MVC 5 app that I added EF later (Data first by the way). Then I deleted the "DefaultConnection" thinking I wouldn't need it. So Identity uses the connection referenced in base. EF uses whatever entity model you set at top of controller.
  • MyModelEntities _db = new MyModelEntities();
  • Thank you @JustJohn, this is FINALLY what worked for me!
  • I have the same problem, I created both connection strings but, where do I say to use one or other connection string?