How does Entity Framework generate a GUID for a primary key value?

asp.net asp.net-mvc c# entity-framework sql-server

Question

The unique id (PK) in the AspNetUser database is automatically established by Entity Framework when the ASP.NET application is started and a user is registered:

enter image description here

Other AspNetRoles, AspNetUserLogins, and AspNetUserRoles are all the same, with the exception of AspNetUserClaims, which has identity enabled.

Could someone please clarify how Entity Framework generates this special ID? And how will we produce this kind of Id for the main key if we want to construct our own table with identity disabled in EF?

1
10
12/21/2016 2:01:00 PM

Accepted Answer

Since the GUID is not produced byEntity Framework nor bySQL . Zzz-11-Zzz is in charge of it. Just go thereIdentityModels.cs

public class ApplicationUser : IdentityUser
{
   // ...
}

This class has been descended fromMicrosoft.AspNet.Identity.EntityFramework.IdentityUser and the definition of this class's function Object() { [native code] } is (Source)

public IdentityUser()
{
    Id = Guid.NewGuid().ToString();
}

So, the function Object() { [native code] } generates the GUID. The other Identity tables also exhibit this.

To be noted, Id Fieldvarchar (string) at the database.

7
4/29/2018 5:36:48 PM

Popular Answer

ZZZ_tmp


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow