📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

When should a many-to-many relationship use an explicit join entity instead of skip navigations?

Intermediate Theory Intermediate

🎯 Key points

  • Skip navigations: link is only two foreign keys
  • Payload columns (date, role, quantity) belong to the relationship, not either side
  • Own identity for audit, soft delete or concurrency on the link
  • UsingEntity<TJoin>() keeps skip navigations with a mapped join class
  • Alternative: two one-to-many relationships to the join entity
  • Same SQL join either way; explicit entity lets you filter, index and page on payload
  • Changing later means a migration and refactoring every query

⏱ 30-second answer

Use skip navigations alone (Student.Courses / Course.Students with a hidden shared-type join table) when the link is just a pair of keys. Switch to an explicit join entity such as Enrolment when the link has payload (enrolment date, role, quantity, price at the time), needs its own identity or audit trail (who linked it, when, soft delete), or is queried or paged on its own. You can keep the convenience of skip navigations and a join class by mapping it with HasMany(...).WithMany(...).UsingEntity<Enrolment>(); or drop the skip navigations and model two plain one-to-many relationships. Performance is similar: both generate the same join through the link table; the explicit entity mainly lets you filter on payload in SQL, project it, and index it, instead of loading links you then discard.

🗣 Full answer (senior)

How I would answer this in an interview

"My test is: does the relationship itself carry facts? A student taking a course is just two keys until the business asks when they enrolled, what grade they got, or who approved it. Those facts belong to the link, so the link becomes an entity, Enrolment, with its own columns and often its own key.

EF Core gives me three shapes. Pure skip navigations, where EF creates a shared-type join entity I never see. Skip navigations backed by my class through UsingEntity<Enrolment>(), so student.Courses still works but I can also query Enrolments with Where(e => e.EnrolledOn >= cutoff). Or no skip navigations at all: Student → Enrolments → Course as two one-to-many relationships, which is clearest when the link is a real domain concept.

Performance is not the deciding factor: all three produce the same join through the link table. What changes is what I can express. With the explicit entity I can filter on payload in SQL, add an index on (CourseId, EnrolledOn), page through enrolments and audit them. I default to the explicit entity when I suspect payload will come, because converting later touches every query."


When to pick which

Shape Fits Cost
Skip navigations only Tags, simple labels No payload, no own audit
UsingEntity<TJoin>() Payload but you like student.Courses Two ways to reach the same data
Two one-to-many Link is a domain concept (Enrolment, OrderLine) Slightly more verbose navigation
modelBuilder.Entity<Student>()
    .HasMany(s => s.Courses)
    .WithMany(c => c.Students)
    .UsingEntity<Enrolment>(j => j.Property(e => e.EnrolledOn).HasDefaultValueSql("sysutcdatetime()"));

Production example

A permissions model started as User ↔ Role skip navigations; an audit requirement (who granted a role, and when) forced an explicit UserRole entity, a migration over [~3 million] rows and changes to [~40] queries. Starting with the explicit entity would have avoided it.

🔍 What the interviewer is checking

Checks modelling judgement.

↩ Usually asked after

More in EF Core Fundamentals

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me