Question

Microsoft.AspNet.Identity.EntityFramework - Objects UserIdentity and RoleIdenity have Id fields of type string, and thus the tables created have data types nvarchar(128).

Shouldn't these objects Id properties be of type System.Guid and the database have datatypes of uniqueidentifier? Why aren't they? A GUID is inserted on new User and Role creation.

Was it helpful?

Solution

Hao Kung from the ASP.NET team wrote this in a comment on this question on how to change id type to int.

So we decided on string keys to avoid having to deal with key serialization issues, the EF default implementation could have used ints as the primary key, GUIDs were just an easy way to generate a random unique string key.

OTHER TIPS

It's most likely because the api is storage provider independent so the kept the field types as generic as possible: http://blogs.msdn.com/b/webdev/archive/2013/06/27/introducing-asp-net-identity-membership-system-for-asp-net-applications.aspx

"If your application requirements are that this information might be stored in a different storage mechanism such as SharePoint, Azure Table Service, No Sql databases etc. it is now possible to plug in different storage providers."

Another reason for a string user ID may be that strings are hard coded into the claims API, specifically, Microsoft.AspNet.Identity.IdentityExtensions.GetUserId, which uses System.Security.Claims.Value, both of which return strings.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top