2

By default, ASP.Net Core Identity uses the type string for the primary key fields of its built-in entities. For example, the IdentityUser class has the property Id as its primary key and its type is string. (This is mapped to type nvarchar(450) in SQL Server)

If find this peculiar, especially since by default the values of these keys are actually string representations of Guids:

    public IdentityUser()
    {
        Id = Guid.NewGuid().ToString();
        SecurityStamp = Guid.NewGuid().ToString();
    }

Why have the designers of ASP.Net Core Identity chosen to use type string for primary keys over, says, type Guid?

urig
  • 16,016
  • 26
  • 115
  • 184

1 Answers1

1

I cannot comment on your question at this time, but I believe this has the answers to the question you are asking:

Why asp.net Identity user id is string?

Second answer from above post: https://stackoverflow.com/a/30029268/11191898

Depending on which version of ASP.Net authentication you're using, on the database ASP.NET Identity v2 should be storing it as a uniqueidentifier (Guid) in the AspNetUsers table. In more preceding versions it will store the user id as an int in the webpages_Membership table.

I believe it surfaces it as a string so it can be any data type you like under the hood and this can then be cast within your code as required.

Community
  • 1
  • 1
MRSessions
  • 316
  • 3
  • 5
  • 1
    Thank you. The second answer in that question suggests the `string` is chosen for the default because it can represent any other data type (serialized). If you'd like to edit your answer to include this information I'll up vote it. :) – urig Apr 16 '20 at 20:45