Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove unique constrant and make username nullable in ASP.NET Identity

I have a series of classes I have overridden for use in ASP.NET Identity 2.0 so that they use the email address field rather than the email field.

When trying to create a user it says The UserName field is required. I have tried overriding the UserName field in my ApplicationUser class which inherits from IdentityUser with [Index(IsUnique = false)] however this just results in a unique constraint and a non-unique index being created.

How can I override the IdentityUser class to make the username nullable and non-unique as I don't want to use it.

Note: I'm fully aware that you can store the email in the username field using the AllowOnlyAlphanumericUserNames property in the UserValidator class. I really don't like this approach and would just like to remove this constraint so I can store the record without a username. I will modify any functions that I need that use the username to look at the email address.

like image 529
Connel Avatar asked Sep 25 '14 08:09

Connel


1 Answers

Here is the full implementation of the IUserStore - http://git.io/XZ3psA I wouldn't say that there is a lot of work.

like image 83
Konstantin Tarkus Avatar answered Oct 28 '22 15:10

Konstantin Tarkus