Why do the UserClaims and RoleClaims tables not accept the Id with the Guid type? #50647
Unanswered
evolution-services
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I already tried according to the documentation:
https://learn.microsoft.com/en-us/aspnet/core/security/authentication/customize-identity-model?view=aspnetcore-7.0
But without success.
I believe this code snippet explains a lot about this:
using System;
using System.Security.Claims;
namespace Microsoft.AspNetCore.Identity;
///
/// Represents a claim that a user possesses.
///
/// The type used for the primary key for this user that possesses this claim.
public class IdentityUserClaim where TKey : IEquatable
{
///
/// Gets or sets the identifier for this user claim.
///
public virtual int Id { get; set; } = default!;
...
}
Where the public virtual int Id { get; set; } = default!; does not allow us to change the type of the property, as it is typed as int.
I believe they could have implemented it as IdentityUser which uses Guid as a key, I don't understand why it should be set to int where we might have more information about the user.
Although int supports a little more than 2 billion records, over time removing and recreating data for example, critical action may be necessary.
Guid would already solve this problem.
I've already made a few attempts and I didn't succeed.
When creating the migration, the result is always the same for the Id column:
migrationBuilder.CreateTable(
name: "AspNetUserClaims",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column(type: "uniqueidentifier", nullable: false),
ClaimType = table.Column(type: "nvarchar(max)", nullable: true),
ClaimValue = table.Column(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
table.ForeignKey(
name: "FK_AspNetUserClaims_AspNetUsers_UserId",
column: x => x.UserId,
mainTable: "AspNetUsers",
mainColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
If anyone knows how to solve it I would be grateful.
Beta Was this translation helpful? Give feedback.
All reactions