Inherit from IdentityUser I get a UserManager <User> error message

I am developing a Web Api 2.2 application with the .NET Framework 4.5.1 and Asp.Net Identity 2.1.0.

I'm not sure what I'm doing, but I want to combine my database with an ASP.NET Identity database, and I did this:

My own dbContext.

public class EFDbContext : IdentityDbContext, IUnitOfWork

My own Userclass.

public class User : 
   IdentityUser<long,
                IdentityUserLogin<long>,
                IdentityUserRole<long>,
                IdentityUserClaim<long>
               >

But when I do this:

UserManager<User> _userManager;

I get this error:

A type Data.Models.Usercannot be used as a type parameter TUser. There is no explicit conversion from Data.Models.Userto Microsoft.AspNet.Identity.IUser<string>.

I do this because I want to have IdentityUser.Idboth longinstead string.

How can I fix this error?

UPDATE

After updating UserManager with

UserManager<User, long> _userManager;

I get three errors here:

EFDbContext_ctx = context as EFDbContext;
_userManager = new UserManager<User, long>(new UserStore<User>(_ctx));
  • "Microsoft.AspNet.Identity.UserManager.UserManager(Microsoft.AspNet.Identity.IUserStore)" -
  • "Data.Models.User" "TUser" "Microsoft.AspNet.Identity.EntityFramework.UserStore". "Data.Models.User" "Microsoft.AspNet.Identity.EntityFramework.IdentityUser".
  • 1: "Microsoft.AspNet.Identity.EntityFramework.UserStore" "Microsoft.AspNet.Identity.IUserStore"

?

+4
2

UserManager

UserManager<User, long> _userManager;

UserManager, :

, .

+5

User, , Identity.

, , :

public class EarlyDetectionContext  
   : IdentityDbContext<User, Role, string, EDLogin, RoleUserAssociation, EDClaim>

, userlogin, userclaim userroles. :

public class EDClaim : IdentityUserClaim<string>
{
}  
public class EDLogin : IdentityUserLogin<string>
{
}
[Table("Roles", Schema = "ED")]
public class Role : IdentityRole<string, RoleUserAssociation>
{
    [Required, Column("DisplayName")]
    public string DisplayName { get; set; }

    [Required, Column("Created")]
    public DateTime Created { get; set; }

    [Required, Column("Updated")]
    public DateTime Updated { get; set; }

    [Required, Column("Deleted")]
    public bool Deleted { get; set; }
}  
[Table("RoleUserAssociations", Schema = "ED")]
public class RoleUserAssociation : IdentityUserRole<string>
{
    //
    //  Due to Identity 2 the Id needs to of string type
    //
    [Key]
    [Required]
    public string ID { get; set; }

    //[Required, Column("User_Id")]
    //public User User { get; set; }

    //[Required, Column("Role_Id")]
    //public Role Role { get; set; }

    [Required, Column("Created")]
    public DateTime Created { get; set; }

    [Required, Column("Updated")]
    public DateTime Updated { get; set; }

    [Required, Column("Deleted")]
    public bool Deleted { get; set; }
}  
[Table("Users", Schema = "ED")]
public class User : IdentityUser<string, EDLogin, RoleUserAssociation, EDClaim>
{
    // This is needed for the new Identity 2 framework
    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<User, string> manager)
    {
        // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
        var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
        // Add custom user claims here
        return userIdentity;
    }

    [Required, Column("Municipality_Id")]
    public Municipality Municipality { get; set; }

    public string PasswordSalt { get; set; }

    [Required, Column("FirstName")]
    public string FirstName { get; set; }

    [Required, Column("LastName")]
    public string LastName { get; set; }

    [Column("Title")]
    public string Title { get; set; }

    [Required, Column("Created")]
    public DateTime Created { get; set; }

    [Required, Column("Updated")]
    public DateTime Updated { get; set; }

    [Required, Column("Deleted")]
    public bool Deleted { get; set; }

    public bool Complete { get; set; }

    [Required]
    public DateTime Activated { get; set; }
}

, , . , . , - , .

GenerateUserIdentityAsync User .

Startup.Auth.cs :

// Configure the db context, user manager and signin manager to use a single instance per request
        app.CreatePerOwinContext(EarlyDetectionContext.Create);
        app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
        app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);  

OWIN ( - " - " ) Identity.cs.

,
, . ( - )
( ).
2.

, :)

+1

All Articles