Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Naming of Navigation-Properties #1342

Closed
WolfgangRoggen opened this issue Apr 14, 2022 · 4 comments
Closed

Naming of Navigation-Properties #1342

WolfgangRoggen opened this issue Apr 14, 2022 · 4 comments
Labels
blocked bug Something isn't working

Comments

@WolfgangRoggen
Copy link

I have a Table TmTvEpisode with a Contraint:
CONSTRAINT [FK_TmTvEpisode_TmTvSeasons] FOREIGN KEY ([ShowId], [SeasonId]) REFERENCES [TmTvSeason]([ShowId], [Id]) ON DELETE CASCADE,

The Foreign key points to the Table TmTvSeason

After running your Tool (setting Plural. = false and "use table and columnnames directly from Database = true) :
In the generatetd Entity TmTvEpisode the Property fort he Foreignkey property is:

public virtual TmTvSeason S { get; set; }

Renaming the table tot he german word „Staffel“ doesnt help.

Steps to reproduce

1st
Create Tables:
CREATE TABLE [dbo].[TmTvPerson]
(
[Id] INT NOT NULL,
[CreditId] NVARCHAR(50) NULL,
[Adult] BIT NULL,
[Gender] TINYINT NULL,
[Name] NVARCHAR(50) NULL,
[OriginalName] NVARCHAR(100) NULL,
[KnownForDepartment] NVARCHAR(20) NULL,
[Popularity] FLOAT NULL,
[ProfilePath] NVARCHAR(75) NULL,
[TheProfile] VARBINARY(MAX) NULL,
CONSTRAINT [PK_TmPerson] PRIMARY KEY ([Id]),
)
CREATE TABLE [dbo].[TmTvEpisode]
(
[Id] INT NOT NULL,
[SeasonId] INT NOT NULL,
[ShowId] INT NOT NULL,
[AirDate] Date NULL,
[EpisodeNumber] INT NULL,
[Name] NVARCHAR(300) NULL,
[Overview] NVARCHAR(MAX) NULL,
[ProductionCode] NVARCHAR(20) NULL,
[SeasonNumber] INT NULL,
[StillPath] NVARCHAR(300) NULL,
[VoteAverage] FLOAT NULL,
[VoteCount] INT NULL,
[TheStill] VARBINARY (MAX) NULL,
[File] NVARCHAR(MAX) NULL,
[TvEpisodeAdded] DATETIME NULL,
[LastView] DATETIME NULL,
[MediaInfo] NVARCHAR(MAX) NULL,
[VideoResolution] NCHAR(10) NULL,
[Codec] NCHAR(100) NULL,
[Gesehen] BIT NULL,
[KodiId] NCHAR(10) NULL,
[KodiPlayCount] INT NULL,
[Runtime] INT NULL,
[FileSize] BIGINT NULL,
CONSTRAINT [PK_TmTvEpisode] PRIMARY KEY ([ShowId], [SeasonId], [Id]),
CONSTRAINT [FK_TmTvEpisode_TmTvSeasons] FOREIGN KEY ([ShowId], [SeasonId]) REFERENCES [TmTvSeason]([ShowId], [Id]) ON DELETE CASCADE,
)
Run your tool with following Settings:
image
image

after that the generatet Entity Episode has a navigation property
public virtual TmTvSeason S { get; set; }
but it should be
public virtual TmTvSeason TmTvSeason { get; set; }

Further technical details

EF Core version in use: EF Core 6

Is Handlebars used: no

EF Core Power Tools: 2.5.918

Database engine: SQL Server

Visual Studio version: Visual Studio 2022

Regards Wolfgang

@ErikEJ
Copy link
Owner

ErikEJ commented Apr 14, 2022

This does not look like a complete repro - I see not definition if the TvSeason table

@WolfgangRoggen
Copy link
Author

Sorry I took the wrong Table.
Instead of TmTvPerson use:
CREATE TABLE [dbo].[TmTvSeason]
(
[Id] INT NOT NULL,
[ShowId] INT NOT NULL,
[AirDate] Date NULL,
[Name] NVARCHAR(300) NULL,
[Overview] NVARCHAR(MAX) NULL,
[PosterPath] NVARCHAR(300) NULL,
[SeasonNumber] INT NULL,
[ThePoster] VARBINARY (MAX) NULL,
[SubDir] NVARCHAR(MAX) NULL,
[TvSeasonAdded] DATETIME NULL,
[Gesehen] BIT NULL,
CONSTRAINT [PK_TmTvSeason] PRIMARY KEY ([ShowId], [Id]),
)

@ErikEJ
Copy link
Owner

ErikEJ commented Apr 18, 2022

I am able to repro, it seems like an EF Core bug, maybe due to your slightly strange primary key design.

Please try using the built-in Scaffold-DbContext command, let me know the outcome.

@ErikEJ
Copy link
Owner

ErikEJ commented Apr 18, 2022

I have created this, that you can follow: dotnet/efcore#27832

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants