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

Add support for many-to-many relations without navigation property #23286

Closed
momvart opened this issue Nov 12, 2020 · 1 comment
Closed

Add support for many-to-many relations without navigation property #23286

momvart opened this issue Nov 12, 2020 · 1 comment

Comments

@momvart
Copy link

momvart commented Nov 12, 2020

Sometimes, it happens that we are only interested in one side of a many-to-many relationship. So, there would be only one navigation property in one of the entries.

Example:

public class Widget 
{
    public int Id { get; set; }
    public string Name { get; set; }
}
public class User
{
    public int Id { get; set; }
    public string Username { get; set; }
    public ICollection<Widget> StarredWidgets { get; set; }
}

This is a question asked on stackoverflow and the accepted answer is this which uses an empty version of WithMany (Entity Framework):

modelBuilder.Entity<User>()
    .HasMany(u => u.StarredWidgets)
    .WithMany() // <- no parameter here because there is no navigation property
    .Map(m =>
    {
        m.MapLeftKey("UserId");
        m.MapRightKey("WidgetId");
        m.ToTable("UserWidgets");
    });

Is it possible to add support for defining this kind of relationship?

@ajcvickers
Copy link
Member

Duplicate of #3864. Make sure to vote for that issue!

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants