C
C#14mo ago
Karbust

❔ Cannot use AspNetUserRoles for type IdentityUserRole

Hello, I'm trying to setup Duende Identity Server 6 and Entity Framework 7 but I'm having issues when trying to query a table in the database context:
System.InvalidOperationException: Cannot use table 'Identity.AspNetUserRoles' for entity type 'IdentityUserRole<string>' since it is being used for entity type 'AspNetUserRoles (Dictionary<string, object>)' and potentially other entity types, but there is no linking relationship. Add a foreign key to 'IdentityUserRole<string>' on the primary key properties and pointing to the primary key on another entity type mapped to 'Identity.AspNetUserRoles'.
System.InvalidOperationException: Cannot use table 'Identity.AspNetUserRoles' for entity type 'IdentityUserRole<string>' since it is being used for entity type 'AspNetUserRoles (Dictionary<string, object>)' and potentially other entity types, but there is no linking relationship. Add a foreign key to 'IdentityUserRole<string>' on the primary key properties and pointing to the primary key on another entity type mapped to 'Identity.AspNetUserRoles'.
It throws that error in this line:
var userInDb = _context.AspNetUsers.FirstOrDefault(u => u.Email == request.Email);
var userInDb = _context.AspNetUsers.FirstOrDefault(u => u.Email == request.Email);
How I'm generating the Context:
dotnet ef dbcontext scaffold "Host=localhost;Database=postgres;Username=postgres;Password=123;" Npgsql.EntityFrameworkCore.PostgreSQL --output-dir ..\Domain\GeneratedEntities --namespace Domain.GeneratedEntities --context GeneratedContext --context-dir ../Persistence/GeneratedContexts --project Persistence.Tooling --startup-project Persistence.Tooling --no-onconfiguring --no-pluralize --force
dotnet ef dbcontext scaffold "Host=localhost;Database=postgres;Username=postgres;Password=123;" Npgsql.EntityFrameworkCore.PostgreSQL --output-dir ..\Domain\GeneratedEntities --namespace Domain.GeneratedEntities --context GeneratedContext --context-dir ../Persistence/GeneratedContexts --project Persistence.Tooling --startup-project Persistence.Tooling --no-onconfiguring --no-pluralize --force
I'm also using this for certain automations: https://github.com/TrackableEntities/EntityFrameworkCore.Scaffolding.Handlebars AspNetUsers:
public partial class AspNetUsers
: IdentityUser<string>
public partial class AspNetUsers
: IdentityUser<string>
AspNetRoles:
public partial class AspNetRoles
: IdentityRole<string>
public partial class AspNetRoles
: IdentityRole<string>
AspNetUserRoles is not being generated. Does anyone know why this error is happening and how can solve it? Thank you
GitHub
GitHub - TrackableEntities/EntityFrameworkCore.Scaffolding.Handleba...
Scaffold EF Core models using Handlebars templates. - GitHub - TrackableEntities/EntityFrameworkCore.Scaffolding.Handlebars: Scaffold EF Core models using Handlebars templates.
1 Reply
Accord
Accord14mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.