aleczandru
aleczandru

Reputation: 5449

Asp.net Identity adding profile data results in error

Hi I am trying to add some profile information to my database using the new ASP.NET Identity Framework.I keep getting this error:

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

This is what I have so far:

private UserManager<User> UserManager
{
        get { return userManager ?? (userManager = new UserManager<User>(UserStore)); }
}
.............
   var user = new User
        {
            UserName = applicationUser.EmailAddress,
            Password = applicationUser.Password,
            BirthDate = applicationUser.BirthDate,
            FirstName = applicationUser.FirstName,
            Gender = applicationUser.Gender,
            IsTermsAndConditionChecked = applicationUser.IsTermsAndConditionChecked,
            LastName = applicationUser.LastName
        };

var identityResult = UserManager.Create(user, user.Password);   

..............

public class User : IdentityUser
{
    public string Password { get; set; }

    public string FirstName { get; set; }

    public string LastName { get; set; }

    public DateTime? BirthDate { get; set; }

    public int Gender { get; set; }

    public bool IsTermsAndConditionChecked { get; set; }
}


public class DbContext : IdentityDbContext<IdentityUser> , IDbContext
{
    public DbContext()
        : base("CodeArtConnectionString")
    {

    }
}

public class AppUserStore : UserStore<User>
{
    private static DbContext dbContext;
    private static IDependencyContainerWrapper dependencyContainer;
    private static IDependencyContainerWrapper DependencyContainer
    {
        get
        {
            return dependencyContainer ?? (dependencyContainer =
                       HttpContextWrapper.Application[GeneralConstants.DEPENDENCY_CONTAINER_KEY] as IDependencyContainerWrapper);
        }
    }

    public static DbContext DbContext
    {
        get
        {
            return dbContext ?? (dbContext = DependencyContainer.Resolve<IDbContext>() as DbContext);
        }
    }

    public AppUserStore() : base(DbContext)
    {

    }
}

Can anyone tel me what I am doing wrong?

Upvotes: 0

Views: 157

Answers (1)

Lin
Lin

Reputation: 15188

I think you need use User instead of IdentityUser in your DbContext class, like below:

public class DbContext : IdentityDbContext<User> , IDbContext
{
    public DbContext()
        : base("CodeArtConnectionString")
    {

    }
}

Upvotes: 1

Related Questions