efcore: Entity Framework 3.0 HasNoKey() for Key less table not working

I am started with .NET Core 3.0 and add ASP.NET Core identity. In tbl_SYS_AspNet_UserRoles there is no primary key. 4xF0v

Steps to reproduce

I scaffold dbcontext and model for another tables in database, using Entity Framework Core tools reference - .NET CLI and Entity Framework generates e.HasNoKey() method in model builder for tbl_SYS_AspNet_UserRoles. I also read doc from Microsoft Documentation . But when I run the project and query for data from another table dbcontext generate , an error:

‘The navigation ‘’ cannot be added because it targets the keyless entity type ‘tbl_SYS_AspNet_UserRoles’. Navigations can only target entity types with keys.’

Further technical details

EF Core version:Microsoft.EntityFrameworkCore Version=“3.0.0” Database provider: Microsoft.EntityFrameworkCore.SqlServer Version=“3.0.0” Target framework: .NET Core 3.0 IDE: Visual Studio Comunity 2019 16.3.5 Full reference of other Asp.Net Core Identity and Entityframework

Microsoft.AspNetCore.Identity Version=“2.2.0” Microsoft.AspNetCore.Identity.EntityFrameworkCore Version=“3.0.0” Microsoft.EntityFrameworkCore Version=“3.0.0” Microsoft.EntityFrameworkCore.Design Version=“3.0.0”
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore Version=“3.0.0”
Microsoft.EntityFrameworkCore.SqlServer Version=“3.0.0” Microsoft.EntityFrameworkCore.Tools Version=“3.0.0” Microsoft.Extensions.Configuration.Json Version=“3.0.0”
Microsoft.Extensions.DependencyInjection.Abstractions Version=“3.0.0”
Microsoft.IdentityModel.Tokens Version=“5.5.0”

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 18 (10 by maintainers)

Most upvoted comments

You are not creating a primary key for tbl_SYS_AspNet_UserRoles!

@ErikEJ If we have a table with no primary key for whatsoever reason, how will this work? I see lot of System.InvalidOperationException: 'The navigation '' cannot be added because it targets the keyless entity type ''. Navigations can only target entity types with keys.' Same as : https://github.com/aspnet/EntityFrameworkCore/issues/18633 ???

You cannot mix version 2 and 3! Update Ms.AspnetCore.Identity