Reverse engineer in EF Core 6 not generating class for a table (works in EF Core 3)
See original GitHub issueThe class for the table dbo.GunnaUserRole is not being genrated in EF Core 6 (is being generated in EF Core 3) . I’m using SQL Server.
Tables:
CREATE TABLE [dbo].[GunnaRole](
[RoleId] [int] IDENTITY(1,1) primary key,
[RoleName] [nvarchar](50) NULL)
CREATE TABLE [dbo].[GunnaUser](
[UserId] [int] IDENTITY(100,1) primary key,
[NationalId] [varchar](10) NULL)
CREATE TABLE [dbo].[GunnaUserRole](
[RoleId] [int] NOT NULL,
[UserId] [int] NOT NULL,
CONSTRAINT PK_GunnaUserRole PRIMARY KEY (RoleId,UserId),
FOREIGN KEY (RoleId) REFERENCES dbo.GunnaRole(RoleId),
FOREIGN KEY (UserId) REFERENCES dbo.GunnaUser(UserId)
)
The generated class (in EF Core 3):
namespace MyAPI.Databases
{
[Table("GunnaUserRole", Schema = "dbo")]
public partial class GunnaUserRole
{
[Key]
public int RoleId { get; set; }
[Key]
public int UserId { get; set; }
[ForeignKey(nameof(RoleId))]
[InverseProperty(nameof(GunnaRole.GunnaUserRole))]
public virtual GunnaRole Role { get; set; }
[ForeignKey(nameof(UserId))]
[InverseProperty(nameof(GunnaUser.GunnaUserRole))]
public virtual GunnaUser User { get; set; }
}
}
I’m using handlebars.
Could it happen that this is a changed behavior? In EF Core 6 the Role property is now in the GunnaUser Class (it was before in the Class GunnaUserRole above):
namespace MyAPI.Databases
{
[Table("GunnaUser", Schema = "dbo")]
public partial class GunnaUser
{
public GunnaUser()
{
Role = new HashSet<GunnaRole>();
}
[Key]
public int UserId { get; set; }
[StringLength(10)]
[Unicode(false)]
public string NationalId { get; set; }
[ForeignKey("UserId")]
[InverseProperty("User")]
public virtual ICollection<GunnaRole> Role { get; set; }
}
}
Thanks, Gunnar
Issue Analytics
- State:
- Created 8 months ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
Scaffolding (Reverse Engineering) - EF Core
Reverse engineering is the process of scaffolding entity type classes and a DbContext class based on a database schema.
Read more >Reverse Engineering Existing Databases with Entity ...
NET developer to do when tasked with integrating and extending existing databases in their Entity Framework Core projects? In this short post, ...
Read more >Entity Framework Core, custom changes and preventing ...
I can run the EF Core Power Tools 'Reverse Engineering' option, refresh my table entities, but not lose any custom data type changes....
Read more >Detect simple join tables in reverse engineering and create ...
The pri-zero here is that a database created by EF6 with many-to-many relationships should reverse-engineer to EF Core with many-to-many ...
Read more >Generating a model from an existing database
In this approach, you reverse-engineer a model from an existing database, resulting in the generation of an EDMX file that contains the model ......
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 FreeTop 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
Top GitHub Comments
@GearTheWorld Correct. And change the target framework in your. Csproj
Oh I see now I understand. I have to go in Nuget Packages and update all