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"?
Asked
Active
Viewed 539 times
2
-
1Possible 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
-
2This is in no way a duplicate, the question was why not how. – Travis Boatman May 26 '17 at 05:53
1 Answers
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