Why is ASP.NET Identity 2.0 using a GUID/string as user id?

后端 未结 5 1850
攒了一身酷
攒了一身酷 2020-12-14 01:07

As the title says, I wonder, why ASP.NET Identity 2.0 uses a string with a GUID as primary clustered key for the user table. Does this have any advantages to an integer id?

5条回答
  •  星月不相逢
    2020-12-14 02:08

    The other answers are excellent, however one advantage I haven't seen mentioned is that Guid.NewGuid() (theoretically) creates a unique ID without committing the row to the database.

    An integer based identity column requires a database flush to get it's ID. There are some circumstances where it's useful to have the PK for your row generated in code and passed to the database (obviously there are other ways of achieving this with with a unique constraint but a Guid is a reasonably good option).

提交回复
热议问题