0

Is it possible to have a many to many relationship in Entity Framework (EF Core), where both sides are the exact same class?

I'm trying to do it with a join table.

So for instance:

public class A {
     public ICollection<A_join_A> This_A_FeaturesManyOther_A { get; set; }
}

public class A_join_A {
     public int SourceAId { get; set; }
     public A SourceA { get; set; }

     public int DestinationAId { get; set; }
     public A DestinationA { get; set; }
}

Then in my DbContext:

builder.Entity<A_join_A>()
.HasKey(t => new { t.SourceAId, t.DestinationAId });
Evan Sevy
  • 641
  • 1
  • 11
  • 21

0 Answers0