2

By default ASP.NET Identity uses GUID for the primary key, however when the database primary key is generated it uses nvarchar - why doesnt it use SQL Data type "UniqueIdentifier"?

enter image description here

001
  • 62,807
  • 94
  • 230
  • 350
  • 1
    Possible duplicate of [How to make EF-Core use a Guid instead of String for its ID/Primary key](https://stackoverflow.com/questions/37166098/how-to-make-ef-core-use-a-guid-instead-of-string-for-its-id-primary-key) – Sami Kuhmonen May 26 '17 at 03:25
  • 2
    This is in no way a duplicate, the question was why not how. – Travis Boatman May 26 '17 at 05:53

1 Answers1

7

The reason why is because the Id property type is a string. In fact all of the primary keys in asp.net core identity are strings with their constructors looking like this...

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

Now the exact reason why is because EF runs on multiple database providers and not all of them have a GUID type. GUID types are quicker as seen here, but unless your working with a huge dataset and need top of the line performance, string type works just fine

Travis Boatman
  • 2,252
  • 16
  • 31