[英]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.当我在Asp.Net
Identity
使用IdentityUser
模型和EntityFramework
,它会在数据库中创建一些标准字段。 All the fields are self explanatory except for the below two fields.除了以下两个字段外,所有字段都是不言自明的。
NormalizedUsername
- Which contains the uppercase value of the Username NormalizedUsername
- 包含用户名的大写值NormalizedEmail
- Which contains the uppercase value of the Email NormalizedEmail
- 包含电子邮件的大写值My doubts are:我的疑问是:
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.在以下线程中对用户名和电子邮件的规范化进行了解释,导致性能降低,并用于验证
UserName
和Email
字段的不区分大小写的唯一性。 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 .它们保存在数据库中,以便能够在它们上创建索引,从而通过规范化的用户名和电子邮件sargable 进行查找。
There is no other reason or usage of these fields.这些字段没有其他原因或用途。
Because in String.Compare("a", "A")
, "a"
is greater than "A"
based on the binary values.因为在
String.Compare("a", "A")
,基于二进制值, "a"
大于"A"
。 The above compare statment translates to String.Compare(01100001, 01000001).上面的比较语句转换为 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.规范化将属性带到
UpperCase
(我相信),其中 SQL 可以按顺序索引UserName
二进制值,而不会出现任何意外的乱序小写字母及其各自的二进制值。
This improves performance when searching or querying the database.这提高了搜索或查询数据库时的性能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.