0
votes

I use ASP.NET Identity 2.0 in my MVC5 project and wanted to change the data type of id field of AspNetUsers from string (GUID) to int because of that I have some tables related to AspNetUsers table. I look at many pages as on How to change type of id in Microsoft.AspNet.Identity.EntityFramework.IdentityUser but it seems to be not easy to apply. On the other hand, I see that changing the data type of id field of AspNetUsers entity will not be enough as there are some pk/fk relations between the other identity types i.e. AspNetUserRoles, ApplicationGroupRoles, etc.. In that case, should I use the original data type for identity tables and change the id type for my tables from int to string? Or how can I change data type of all of the identity tables easily in ASP.NET Identity 2.0? If this is easier in version 3.0 I can also use it.

1
Why you don't let Users with string Id and all others tables with int Id?Lucian Bumb
@LucianBumb I am not sure if it is good idea for PK/FK relation. So, I think the best idea is to use int for custom tables and convert id type from string to int for asp.net identity tables. Any suggestion?Jack
mate, I struggle a lot to do what you are trying now, because I was sure that I cannot have string Id in some entities, and int in other entities, till I decide to make a test and see what will be the problem. The result was no problem! you just need to take care, that userId is string.Lucian Bumb

1 Answers

0
votes

I want to extend my comment because, few months ago I was trying to do the same.

In my case, I was not sure if I can create relations string -> int, comming from Database first, and used to create relations between productId(int) and userId(int), I wanted to have int ids all over.

Mate you can let userId like string and create relations like this;

public class Customer
{
  public int Id {get;set;}
  public string Name {get;set;}

  public string SalesManId {get;set;}
  [ForeignKey("SalesManId ")]
  public virtual ApplicationUser SalesMan {get;set;}
}

Here is the Customer Entity, and I have declared a navigation property! So, the SalesManId is of type string. In this way you can create all your relations with ApplicationUser class.

If you still want to change to int, here is a youtube tutorial, which I followed few months ago and I manged to change from string to int

YouTube tutorial-How to change UserId from string to int