The ASP.NET Identity code for MVC/EF stores the userid as a nvarchar(128). This looks like a GUID. I prefer using sequential GUIDs for an ID/Private Key to improve performance. How can I verify that the code generating the GUID for ASP.NET Identity is sequential? I'm having trouble finding that part of the code base.
2 Answers
Identity is built to work with different persistence technologies. I even seen the implementations of Identity storing data on Azure Tables which is not relational database.
Sequential GUID is only a feature of SQL Server and even not every version of SQL Server supports Sequential GUID (SQL Azure does not know about sequential GUIDs for example).
But if you set User.Id to be of type Guid and use SQL Server that supports sequential ids, your tables will be created with Ids of type sequentialguid.
I can verify that - I had troubles with types a few times trying to port locally created DB into Azure SQL.
Update
What I recommend is to change ID into Guid - same as other recommendations to make it int - you'll find plenty of guides online how to do it. The place where ID is generated is here:
namespace Microsoft.AspNet.Identity.EntityFramework
{
/// <summary>
/// Default EntityFramework IUser implementation
///
/// </summary>
public class IdentityUser : IdentityUser<string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>, IUser, IUser<string>
{
public IdentityUser()
{
this.Id = Guid.NewGuid().ToString();
}
public IdentityUser(string userName)
: this()
{
this.UserName = userName;
}
}
}
This is part of the framework from a decompiler. It is most likely you already inherit from this class to create your own ApplicationIdetntityUser.
However, if you so keen on sequential guid, the most safe way for that is to let SQL Server to create them for you. And you can do by adding [DatabaseGenerated(DatabaseGeneratedOption.Identity)] on Guid Id property of your user object.
You can generate sequential guids yourself, but eventually you will run into collision from different threads. I suggest you don't waste your time and let SQL Server to do the job for you - there are inbuilt mechanisms there.
Int32instead ofGUID, why do you bothered about the performance? If its a PK on the table, it is indexed. - Ofiris