many-to-many documentation here doesn't seem to work.
Could be something I'm missing of course, but I've tried several times following along with the code examples and the many-to-many relationship code doesn't seem to work.
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
- ID: 24b2b50e-35f8-9e0b-8ce5-840e1ea816e6
- Version Independent ID: 9e0e6e2c-48fa-76c3-3bd9-813a6df22645
- Content: Relationships - EF Core
- Content Source: entity-framework/core/modeling/relationships.md
- Product: entity-framework
- Technology: entity-framework-core
- GitHub Login: @AndriySvyryd
- Microsoft Alias: avickers
@jsangco What, specifically, doesn't work?
Follow the example code in the provided documentation. The many-to-many relationship does not work.
After spending quite a bit of time debugging it, I figured out that it is due to the fact that EFCore does not pluralize its DbSet names anymore. This is problematic for people using a DB first method expecting the singular table names to map to pluralized proprieties.
Additionally, there's just generally poor consistency with table and property names in the sample code; thus leading to confusion. For example, the document has a table definition like this:
CREATE TABLE [PostTag] (
[PostsId] int NOT NULL,
[TagsId] nvarchar(450) NOT NULL,
CONSTRAINT [PK_PostTag] PRIMARY KEY ([PostsId], [TagsId]),
CONSTRAINT [FK_PostTag_Posts_PostsId] FOREIGN KEY ([PostsId]) REFERENCES [Posts] ([PostId]) ON DELETE CASCADE,
CONSTRAINT [FK_PostTag_Tags_TagsId] FOREIGN KEY ([TagsId]) REFERENCES [Tags] ([TagId]) ON DELETE CASCADE
);
Then later has code like this (Please note the additional s in the name)
j.ToTable("PostTags"));
I would recommend going through the sample code for the many-to-many relationship and ensuring it can be used to execute working code (for both code-first and db-first if possible).