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

5.0 RC1 Many-to-many optional navigation properties #22627

Closed
Atulin opened this issue Sep 20, 2020 · 2 comments
Closed

5.0 RC1 Many-to-many optional navigation properties #22627

Atulin opened this issue Sep 20, 2020 · 2 comments

Comments

@Atulin
Copy link

Atulin commented Sep 20, 2020

Right now, it seems that the necessary code to create many-to-many is

class Post
{
  public int Id { get; set; }
  public ICollection<Tag> Tags { get; set; }
}

class Tag
{
  public int Id { get; set; }
  public ICollection<Post> Posts { get; set; }
}
builder.Entity<Post>()
  .HasMany(p => p.Tags)
  .WithMany(t => t.Posts);

but what about optional navigation properties, when I want only Post to have a list of Tags, but not necessarily the Tag to have a list of Posts?

class Post
{
  public int Id { get; set; }
  public ICollection<Tag> Tags { get; set; }
}

class Tag
{
  public int Id { get; set; }
}
builder.Entity<Post>()
  .HasMany(p => p.Tags)
  .WithMany();

That would also be in line with other relationships, where

builder.Entity<Post>()
  .HasOne(p => p.Category)
  .WithMany();

is perfectly valid and doesn't require a Category to contain a collection of Posts.

@ajcvickers
Copy link
Contributor

Related/dupe: #3864

@ajcvickers
Copy link
Contributor

@Atulin This isn't supported for 5.0. I've updated #3864 to indicate that this is the issue tracking unidirectional many-to-many relationships. Please 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