'How to add auto-increment column in aspnetuser table while implementing asp.net identity?
How to add auto-increment column in AspNetUsers table while implementing asp.net identity? I do not prefer to change much the existing code and any simple workaround is also fine for me.
Solution 1:[1]
If you are just looking for a column which value will auto increment (as per your question) then just add a column to the AspNetUsers table and make it auto incremental.
Personid int NOT NULL AUTO_INCREMENT,
By default, the starting value for AUTO_INCREMENT is 1, and it will increment by 1 for each new record.
Solution 2:[2]
To add an autoincrement column named "PersonId" in AspNetUsers table:
public class AppUser : IdentityUser
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public string PersonId { get; set; }
}
Then add-migration and update-database.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Rahatur |
Solution 2 | Alfi |