What is the use of Normalized Email & UserName in .NET core IdentityUser Model?

When I use IdentityUser model in Asp.Net Identity with EntityFramework, it creates some standard fields in the database. All the fields are self explanatory except for the below two fields.

  • NormalizedUsername – Which contains the uppercase value of the Username
  • NormalizedEmail – Which contains the uppercase value of the Email

My doubts are:

  1. Why do we need these Normalized fields? Where does it get used?
  2. What is the purpose of persisting it in the database?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

By my understanding, both fields are there for performance reasons. It’s sort of explained in the following thread Normalization on UserName and Email causes slow performance and are used to validate the case insensitive uniqueness of the UserName and Email fields. They are persisted in the database in order be able to create index on them, thus making the lookups by the normalized user name and email sargable.

There is no other reason or usage of these fields.

Method 2

Because in String.Compare("a", "A"), "a" is greater than "A" based on the binary values. The above compare statment translates to String.Compare(01100001, 01000001). As you can see one value is greater than the other.

Normalization brings the property to UpperCase (I believe) where SQL can index the UserName binary values sequentially without any surprise out of sequence lower case letters and their respective binary values.

This improves performance when searching or querying the database.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x