Cannot use table 'AspNetRoles' for entity type 'AspNetRole' since it is being used for entity type 'IdentityRole' and potentially other entity types, but there is no linking relationship.
See original GitHub issueFile a bug
I am using Db first approach using latest EF version in DOTNET 6. It does not generate AspNetUserRole table and add dictionary details as
modelBuilder.Entity<AspNetUser>(entity =>
{
entity.HasIndex(e => e.UserName, "UserNameIndex")
.IsUnique();
entity.Property(e => e.Id).HasMaxLength(128);
entity.Property(e => e.Email).HasMaxLength(256);
entity.Property(e => e.LockoutEndDateUtc).HasColumnType("datetime");
entity.Property(e => e.UserName).HasMaxLength(256);
entity.HasMany(d => d.Roles)
.WithMany(p => p.Users);
.UsingEntity<Dictionary<string, object>>(
"AspNetUserRole",
l => l.HasOne<AspNetRole>().WithMany().HasForeignKey("RoleId").HasConstraintName("FK_dbo.AspNetUserRoles_dbo.AspNetRoles_RoleId"),
r => r.HasOne<AspNetUser>().WithMany().HasForeignKey("UserId").HasConstraintName("FK_dbo.AspNetUserRoles_dbo.AspNetUsers_UserId"),
j =>
{
j.HasKey("UserId", "RoleId").HasName("PK_dbo.AspNetUserRoles");
j.ToTable("AspNetUserRoles");
j.HasIndex(new[] { "RoleId" }, "IX_RoleId");
j.HasIndex(new[] { "UserId" }, "IX_UserId");
j.IndexerProperty<string>("UserId").HasMaxLength(128);
j.IndexerProperty<string>("RoleId").HasMaxLength(128);
});
});
Now, when I am trying to use Microsoft.AspNetCore.Identity.EntityFrameworkCore method to get user details using FindByLoginAsync method. I get the error

My Program.cs is configured as:

I also tried by manually adding the table AspNetUserRole and adding the relationships as

Please download the project from https://drive.google.com/file/d/14zmk-jijpYPbyzwOkJ63OPBMM44CHkSY/view?usp=sharing
I would be grateful if you help as ASAP. Thanks
Include provider and version information
EF Core version: 6.0.1 Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer) Target framework: (e.g. .NET 6.0) Operating system: IDE: (e.g. Visual Studio 2019 16.3)
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Cannot use table 'AspNetUsers' in schema '' for entity ...
Cannot use table 'AspNetUsers' in schema '' for entity 'AspNetUsers' since it is being used for another entity. There is no other dbContext ......
Read more >Cannot use table 'AbpUsers' for entity type 'IdentityUser' since ...
ABP Framework version: v5.2.0 UI type: MVCr DB provider: EF Core Tiered (MVC) ... and potentially other entity types, but there is no...
Read more >Access To User in AspNetUserRoles table - Microsoft Q&A
Hi,. in this code i want get user (ApplicationUser.cs) in AspNetUserRole tb , but just two field exists UserId,RoleId. 187226-untitled.png.
Read more >The entity type IdentityUserLogin requires a primary key to be ...
Your browser can't play this video. Learn more.
Read more >ASP.NET Core Identity 3.0 : Modifying the Identity Database
I simply have to issue the dotnet ef database update command and it will deploy the database to the connection string located in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I am getting the same error as you: adil-portable in a web .net 6 api.
Very odd. No fix yet!
Thanks Graham
@adil-portable use the advanced option to actually generate an entity