Closed janseris closed 6 months ago
If you want free support, you must provide repro scripts, not screenshots, and you must use the latest released version of the tool.
Thanks I will try latest version
If you want free support, you must provide repro scripts, not screenshots, and you must use the latest released version of the tool.
I have been sponsoring you on GitHub for 21 months btw. This issue is not resolved in latest EF Core Power Tools version.
Many to many entity is created with both EF Core 7 and 8 settings. The settings are as shown in screenshots above.
The database script is here. The database is nothing special.
USE [DatabaseName]
GO
/****** Object: Table [dbo].[GLOBAL_ROLE] Script Date: 05.05.2024 23:44:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[GLOBAL_ROLE](
[ID] [int] NOT NULL,
[Nazev] [nvarchar](50) NOT NULL,
CONSTRAINT [PK_GLOBAL_ROLE] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[USER] Script Date: 05.05.2024 23:44:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[USER](
[ID] [int] NOT NULL,
[Jmeno] [nvarchar](50) NOT NULL,
[Prijmeni] [nvarchar](50) NOT NULL,
[TitulyPredJmenem] [nvarchar](10) NULL,
[Email] [nvarchar](50) NOT NULL,
[Firma] [nvarchar](100) NULL,
CONSTRAINT [PK_UZIVATEL] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[V_USER__GLOBAL_ROLE] Script Date: 05.05.2024 23:44:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[V_USER__GLOBAL_ROLE](
[UserID] [int] NOT NULL,
[GlobalRoleID] [int] NOT NULL,
CONSTRAINT [PK_V_USER__GLOBAL_ROLE] PRIMARY KEY CLUSTERED
(
[UserID] ASC,
[GlobalRoleID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[V_USER__GLOBAL_ROLE] WITH CHECK ADD CONSTRAINT [FK_V_USER__GLOBAL_ROLE_GLOBAL_ROLE] FOREIGN KEY([GlobalRoleID])
REFERENCES [dbo].[GLOBAL_ROLE] ([ID])
GO
ALTER TABLE [dbo].[V_USER__GLOBAL_ROLE] CHECK CONSTRAINT [FK_V_USER__GLOBAL_ROLE_GLOBAL_ROLE]
GO
ALTER TABLE [dbo].[V_USER__GLOBAL_ROLE] WITH CHECK ADD CONSTRAINT [FK_V_USER__GLOBAL_ROLE_USER] FOREIGN KEY([GlobalRoleID])
REFERENCES [dbo].[USER] ([ID])
GO
ALTER TABLE [dbo].[V_USER__GLOBAL_ROLE] CHECK CONSTRAINT [FK_V_USER__GLOBAL_ROLE_USER]
GO
Very strange that this does not happen for all M:N relations. For this relation, the code is generated correctly:
I am not able to spot any difference between these two:
I also tried deleting EFPT config json and trying again but received the same result.
I could not reproduce with new database with isolated tables, so in attachment I am enclosing script for whole database and tables (note: files with .sql extension cannot be attached, so I changed the extension to .txt). create database.txt
Your sponsorship is highly appreciated.
Thanks for the scripts I will have a closer look.
@janseris This foreign key is wrong, so the table is not a proper many to many table:
ALTER TABLE [dbo].[V_USER__GLOBAL_ROLE] WITH CHECK ADD CONSTRAINT [FK_V_USER__GLOBAL_ROLE_USER] FOREIGN KEY([GlobalRoleID])
REFERENCES [dbo].[USER] ([ID])
It should most likely be something like:
ALTER TABLE [dbo].[V_USER__GLOBAL_ROLE] WITH CHECK ADD CONSTRAINT [FK_V_USER__GLOBAL_ROLE_USER] FOREIGN KEY([UserID])
REFERENCES [dbo].[USER] ([ID])
after making that changes, it get this:
public partial class User
{
public int Id { get; set; }
public string Email { get; set; }
public virtual ICollection<GlobalRole> GlobalRoles { get; set; } = new List<GlobalRole>();
}
Ohhhhhh I am sorry. Thanks for pointing it out.
No problem, there usually is a good explanation! 😄
Incorrectly generates join entity. Expected result: User has GlobalRole navigation property and the entity is not generated.
The schema goes like this (primary key consists of two foreign keys in the M:N join table):
EF Core Power Tools version: 2.5.1718
Exact Visual Studio version: (e.g. Visual Studio 2022 17.9.5)
Database engine: SQL Server
EF Core version in use: EF Core 7 but used schema generating option EF Core 8 because there is none else
Is Handlebars templates used: no
Is T4 templates used: no
Is a SQL Server .dacpac used: no