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

How to configure a many-many relationship without two navigational properties? #23155

Closed
GurGaller opened this issue Oct 30, 2020 · 1 comment

Comments

@GurGaller
Copy link

GurGaller commented Oct 30, 2020

Is there a way to configure a many-many relationship where the second entity has no navigation property?
Looking at the overloads of CollectionNavigationBuilder<TEntity, TRelatedEntity>.WithMany, all of them require a property to be passed.
I expected a similar API to WithOne, that has an overload with an optional parameter.

Another thing I noticed is that the documenation of the overload that takes a lambda expression states that:

If no property is specified, the relationship will be configured without a navigation property on the other end of the relationship.

But how can we call that method without a property?

Example

Let's say we have these two classes:

public class Product
{
    public int Id { get; set }
    public IEnumerable<Category> Categories { get; set; }
}
public class Category
{
    public int Id { get; set; }
}

I expected the following configuration to work, but it doesn't compile:

public class ProductTypeConfiguration : IEntityTypeConfiguration<Product>
{
    public void Configure(EntityTypeBuilder<Product> builder)
    {
        builder.HasMany(p => p.Categories).WithMany();
    }
}

Provider and version information

EF Core version: 5.0.0-rc.2.20475.6
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 5.0
Operating system: Windows 10
IDE: Visual Studio 2019 16.8.0 Preview 6.0

@ajcvickers
Copy link
Contributor

@GurGaller This is tracked by #3864

@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