简体   繁体   English

.NET 核心 IdentityUser 模型中规范化电子邮件和用户名的用途是什么?

[英]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:我的疑问是:

  1. Why do we need these Normalized fields?为什么我们需要这些标准化字段? Where does it get used?它在哪里使用?
  2. What is the purpose of persisting it in the database?将它持久化到数据库中的目的是什么?

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.在以下线程中对用户名和电子邮件的规范化进行了解释,导致性能降低,并用于验证UserNameEmail字段的不区分大小写的唯一性。 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.

相关问题 在ASP.NET中使用IdentityUser进行电子邮件验证 - Email Validation with IdentityUser in ASP.NET 从 Asp Net MVC 中的 IdentityUser 中排除 email - Exclude email from IdentityUser in Asp Net MVC (asp.net core mvc)如何在UI层中使用identityUser与实体层中的产品 - (asp.net core mvc) How can I use identityUser in UI layer with product in entity layer 在 ASP.NET Core MVC 中实现身份验证时是否应该使用“IdentityUser” - Should I use 'IdentityUser' when I implement an authentication in ASP.NET Core MVC ASP.NET Core:如何使用“用户名”而不是“电子邮件”登录? - ASP.NET Core : How to login with “UserName” instead of “Email”? 在 ASP.NET Core MVC 中注册唯一的 email 或唯一的用户名 - Register with unique email OR unique username in ASP.NET Core MVC 如何通过用户名获取 IdentityUser - How to get IdentityUser by Username ASP.NET身份-验证IdentityUser上唯一的用户电子邮件地址 - ASP.NET Identity - Validation for unique user email address on IdentityUser ASP Net Core:与IdentityUser添加多对多关系 - ASP Net Core: add many to many relationship with IdentityUser Asp.net 核心中的 FriendSystem 使用 IdentityUser 和 EntityFramework - FriendSystem in Asp.net core using IdentityUser and EntityFramework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM