How to make an int field named UserID as the primary key in AspNetUsers table in Asp.Net Core 6.0 MVC

Sherpa 241 Reputation points
2024-05-24T17:41:58.43+00:00

I am implementing Asp.Net Core Identity on an existing legacy website. I have created the Identity tables using migrations. The legacy database has a table named Users which was used for the logging. I have replaced the Users table with the AspNetUsers table. The legacy table had a field named UserID which was int as well as a primary key. I have modified the AspNetUsers table by adding a field named UserID of type int and moved all the rows from the Users table to the AspNetUsers table. The AspNetUsers table by default has ID field as the primary key which is a GUID. Is there a way to make the UserID the primary key in the AspNetUsers table?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,401 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AgaveJoe 27,696 Reputation points
    2024-05-24T18:57:41.09+00:00

    Identity allows you to configure the primary key. The official documentation covers the details with source code.

    Change Primary Key for Users in ASP.NET Identity