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

与世无争的帅哥 提交于 2020-12-29 05:04:26

问题


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?

回答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.




回答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.



来源:https://stackoverflow.com/questions/41409692/what-is-the-use-of-normalized-email-username-in-net-core-identityuser-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!