Skip to content

many-to-many documentation here doesn't seem to work. #4053

Closed

Description

@jsangco

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.

Activity

  1. ajcvickers commented on Sep 26, 2022

    @ajcvickers
    Contributor

    @jsangco What, specifically, doesn't work?

  2. jsangco commented on Sep 30, 2022

    @jsangco
    Author

    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).

  3. added this to the Backlog milestone on Oct 5, 2022
  4. self-assigned this
    on Feb 23, 2023
  5. modified the milestones: Backlog, 8.0.0 on Feb 23, 2023
  6. added 8 commits that reference this issue on Feb 25, 2023
    e20432f
    671a66c
    94ff962
    f33e5ed
    c7b38aa
    93b4c5e
    1ba858c
    bb39d2d
  7. added a commit that references this issue on Mar 19, 2023
    9a1e6f2
  8. added 2 commits that reference this issue on Mar 28, 2023
    f5d7299
    dd7c736
  9. removed their assignment
    on Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions