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

Code example calls a method with lambdas as parameters, where the lambda parameter names are the opposite of what the method labels them. #4846

Open
jphorv-bdo opened this issue Oct 24, 2024 · 0 comments · May be fixed by #4866

Comments

@jphorv-bdo
Copy link

Type of issue

Other (describe below)

Description

In the docs about how to configure many-to-many relationships with a class for a join entity:

https://learn.microsoft.com/en-us/ef/core/modeling/relationships/many-to-many#many-to-many-with-class-for-join-entity

The code sample looks like this:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<Post>()
        .HasMany(e => e.Tags)
        .WithMany(e => e.Posts)
        .UsingEntity<PostTag>(
            l => l.HasOne<Tag>().WithMany().HasForeignKey(e => e.TagId),
            r => r.HasOne<Post>().WithMany().HasForeignKey(e => e.PostId));
}

The call to UsingEntity<PostTag>() has those 2 lambdas, the first one with a parameter of l and the 2nd with a parameter named r, suggesting "left" and "right".

The problem is that the UsingEntity method signature has those reversed, where "right" is first, then "left". Like this: UsingEntity(Func<...> configureRight, Func<...> configureLeft) The sample suggests the parameter order is (left, right) when in actuality it is (right, left).

Yes, type checking should prevent the user from doing something invalid, but it may confuse developer as to what is considered "left" and what is considered "right".

Page URL

https://learn.microsoft.com/en-us/ef/core/modeling/relationships/many-to-many#many-to-many-with-class-for-join-entity

Content source URL

https://github.com/dotnet/EntityFramework.Docs/blob/main/entity-framework/core/modeling/relationships/many-to-many.md

Document Version Independent Id

9234f104-802f-8ee0-8a54-ff3b8f49857e

Article author

@ajcvickers

@timdeschryver timdeschryver linked a pull request Nov 6, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant