M
M
Mikhail2018-01-31 20:27:45
.NET
Mikhail, 2018-01-31 20:27:45

How to remove unnecessary data from the user table when registering through Identity?

I do here authorization through Identity. Created a user model that I inherited from IdentityUser. And if I do not specify UserName when registering a new user, then I get an error that this field is required. But if I don't need this field in my model, what should I do?
Tried via user-validation with no success.
PS Core 2.0

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-01-31
@alexr64

That's just not getting rid of UserName. IdentityUser is an implementation of the IUser interface . You can take the Identity sources and change the IUser interface.
Or you can try to cover the UserName with an email and exclude it from the database model. Then, in theory, UserName will not participate in any way, but in practice I did not check it.

public class MyUser:IdentityUser
{ 
       [AlwaysValid] //Всегда валидно
        [NotMapped] //не маппим в EFCore
        public string UserName
            {
                get => Email;
                set => Email = value;
            }
}
        public class AlwaysValid : ValidationAttribute
{
                public override bool IsValid(object value) => true;
                   
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question