khalid Saud
khalid Saud

Reputation: 147

Entity Framework IdentityUser override UserName will not be saved in database

I had issue with Entity Framework IdentityUser when override UserName and then try to create new user the UserName will not be saved in database even though the normlized username is saved.

Same issue happens to Email when I override.

I have been using it this way for years in many projects with no issues, but in this I couldn't find out why it is happening.

if I remove the override attribute then it will be saved in database fine, but i do need override.

Please assist.

enter image description here

enter image description here

enter image description here

Upvotes: 2

Views: 919

Answers (1)

Farshad Delavarpour
Farshad Delavarpour

Reputation: 205

Did you pass your User class to the IdentityDbContext?

In the applicationDbContext where you inherit the IdentityDbContext, if you have your own specific User or Role classes you must pass these classes to the IdentityDbContext.

public class ApplicationDbContext: IdentityDbContext<UserClass, RoleClass, TKey>{}

And also in the StartUp.cs class, you must add these classes where you add identity services.

services.AddIdentity<UserClass, RoleClass>();

Upvotes: 2

Related Questions