question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support unidirectional many-to-many relationships

See original GitHub issue

Support shadow navigation properties such that views over the navigations can function even when a CLR type doesn’t have an actual navigation property. This would enable unidirectional many-to-many relationships like this:

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();

Original issue:

Are there any plans to support this?

table.Include(t => EF.Property<Entity>(t, "Property"))

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:90
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

7reactions
freer4commented, Feb 25, 2022

Just a heads up, the documentation clearly states that single-property navigation is possible via a parameterless WithMany()

https://docs.microsoft.com/en-us/ef/core/modeling/relationships?tabs=fluent-api%2Cfluent-api-simple-key%2Csimple-key#single-navigation-property-1

As of 6.0.2 this does not work, who is in charge of the docs?

2reactions
anranruyecommented, Dec 23, 2020

I think using the following code may help to hide many-to-many navigation properties from out of entity types with current EF Core version(5.0.1)

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

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

builder.Entity<Post>()
  .HasMany(p => p.Tags)
  .WithMany("Posts");

Just mark the Posts property as private, ef core can work well and you can still use this navigation property inside Tag class. I prefer to field-only property, but it will make both navigations can not be loaded by explicit loading. See at #23717.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JPA ManyToMany unidirectional relationship
Lets say we have two Entities, Entity Node and Entity Cluster . A Cluster has many Node s. A Node can belong to...
Read more >
Hibernate @ManyToMany Unidirectional and Bidirectional
The Many-to-Many relationship can be best described by example. The example we're going to use is that of the relationship between an Author...
Read more >
Introduction to Spring Data JPA Part 7: Unidirectional Many ...
In this article, we discuss how to create many-to-many, unidirectional relationships with Spring Data JPA.
Read more >
Association Mappings with JPA and Hibernate
The bidirectional mapping models the relationship for both entities so that you can navigate it in both directions. The concept for the mapping...
Read more >
Hibernate many-to-many unidirectional relationship
In the post, we are going to discuss a many-to-many unidirectional hibernate relationship. Many-to-many unidirectional relationship. We are ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found