Sami-L
Sami-L

Reputation: 5705

ASP.Net Core - How to add a new field to the default Microsoft Identity structure

Using ASP.Net Core 2.1, I am trying to add a new field to the default Microsoft Identity Users table structure, so I created a new model that I used in the project database context to inherit from Microsoft.AspNetCore.Identity, I used to implement the following code successfully but this time I got error.

Here is the model:

public class ApplicationUser : IdentityUser
{
    public string Age { get; set; }
}

Here is the database context:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser, string>
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
    public string CurrentUserId { get; set; }
}

And here is the output error:

The non-generic type 'IdentityDbContext' cannot be used with type arguments

What am I doing wrong here ?

Upvotes: 0

Views: 403

Answers (1)

Stefan
Stefan

Reputation: 17648

I am not sure, but I don't see a base constructor which accepts those 2 type arguments.

See MSDN

Valid type arguments are:

//none
public class IdentityDbContext

or

//application user
public class IdentityDbContext<TUser> 

or

//Thanks to @ Ivvan
public class IdentityDbContext<TUser,TRole,TKey>

or

//the full version
public class IdentityDbContext<TUser, TRole, TKey, TUserLogin, TUserRole, TUserClaim>

So in your case, I think you meant:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>

Upvotes: 1

Related Questions