greedyLump
greedyLump

Reputation: 250

Customize the primary key data type for Identity in asp.net core 2 creates problems in UserStore

I need the primary key for my user class in Identity to be long instead of the default string. Following this MS tutorial. So i do all that (just replace GUID in the tutorial with long) and everything was looking good until I was working on created a seed class

var userStore = new UserStore<ApplicationUser>(context);

gives me the squiggles on ApplicationUser with the message:

Error CS0311 The type 'WSCPA_AC.Models.ApplicationUser' cannot be used as type parameter 'TUser' in the generic type or method 'UserStore'. There is no implicit reference conversion from 'WSCPA_AC.Models.ApplicationUser' to 'Microsoft.AspNetCore.Identity.IdentityUser'.

Now I see mention of this sort of problem in the comments at the bottom of the tutorial. Do I have to somehow override the UserStore class, and if so, how?

Upvotes: 0

Views: 378

Answers (1)

SpruceMoose
SpruceMoose

Reputation: 10320

I think you will need to use the base class of UserStore which has a signature of UserStore<TUser, TRole, TContext, TKey> as follows:

var userStore = new UserStore<ApplicationUser, IdentityRole<long>, TContext, long>(context);

Where TContext is the type of your database context.

Upvotes: 3

Related Questions