0

I use ASP.NET Identity in an MVC project and I need to create entity relation between ASP.NET Identity AspNetUsers entity and my custom tables. As it is known, AspNetUsers table uses string for Id field and there is GUID values in this Id field. However, I am not sure about the issues below:

1) What data type should I use in my custom classes in order to create PK/FK relation? string or GUID?

2) How can I make this custom Id field to be generated automatically for every new record? Is it also possible to make it sequential so that the records can be sorted?

Jack
  • 1
  • 21
  • 118
  • 236

1 Answers1

1

1-You should use string. (see this)

If you open the edmx you see that Id(GUID) in AspNetUser is string.

2-You can use constructor in model and generate GUID filed in it like this:

public partial class Student
{
    public Student()
    {
        Id = System.Guid.NewGuid().ToString();
    }
    //Other fileds
}

3- for Sequential Guid Generator see this.I suggest UuidCreateSequential.

Community
  • 1
  • 1
Ali Soltani
  • 9,589
  • 5
  • 30
  • 55
  • Selam Ali, Thanks for reply. In that case: **1)** Ok, I use string and keep GUID values in it. But I am not sure if I have to use anything special in this Entity. Is your example is suitable for it? **2)** Could you please give an example implementation? **3)** There are several answer on that page. Which one do you suggest? – Jack Aug 04 '16 at 19:49