Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using navigation properties does not allow to use some methods from UserManager or RoleManager #60

Open
wieczorekmichal1 opened this issue Nov 10, 2023 · 0 comments

Comments

@wieczorekmichal1
Copy link

I went through a guide describing how to configure navigation properties for the identity package and encounter a problem with relations between defined navigation properties, causing problem with eg. assinging role to user.

Steps to reproduce:

  1. Configure database context with the navigation properties eg. UserRoles link to source.
  2. Add application user using UserManager<ApplicationUser> with method CreateAsync.
  3. Add role using RoleManager<ApplicationRole> with method CreateAsync.
  4. Confirm that user and role are added to database.
  5. Assign role to the user using UserManager<ApplicationUser> with method AddToRoleAsync.
  6. Observe that there is new entry in UserRole table which is correct, but with incorrect UserId and RoleId, which does not exist and was generated with running previous step.

Users:
image

UserRoles:
image

Roles:
image

I checked assigning role to user directly using ApplicationDbContext, which was successful and no ghost entries were added to Users and Roles tables:

context.UserRoles.Add(new ApplicationUserRole
{
    RoleId = adminRole.Id,
    Role = adminRole,
    UserId = admin.Id,
    User = admin,
});

The same situation happens when using other navigation properties like IdentityClaims and etc.

Issue reproduced with:

  • PostgreSQL 16
  • .NET 6
  • Microsoft.AspNetCore.Identity.EntityFrameworkCore 6.0.24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant