efcore icon indicating copy to clipboard operation
efcore copied to clipboard

many-to-many relationships without a joining entity

Open zanate4019 opened this issue 8 years ago • 6 comments

I know this probably gets asked a lot, but is adding support for many-to-many relationships without a joining entity on the roadmap? If so where?

Jason

zanate4019 avatar Jul 18 '18 14:07 zanate4019

How do u imagine many to many withour midle entity ?

By concept many many must use 3 entity !

Diaskhan avatar Jul 18 '18 19:07 Diaskhan

It does currently in EF 6.x and previous versions of EF as well as in Resharper. I know linking tables are necessary in relational databases for many-to-many relationships, but they dont make a lot of logical sense in entities.

zanate4019 avatar Jul 18 '18 19:07 zanate4019

The ef core is some kind new orm library! I think they not gona do some incorect errorrs in conceptual architecture!

Diaskhan avatar Jul 19 '18 02:07 Diaskhan

Many-to-Many relationships without a linking entity is not incorrect. In fact it makes more sense in an object oriented world because linking entities have no real world parallel. I hate the idea that I have to pollute my domain or use DTOs unnecessarily because my ORM doesn't support this.

Here's a common example. You have courses that have many students. Each student can be in many courses. Classic many-to-many. In a relational database I create a Students table, a Courses table, and a StudentCourses table to link them. In OOP, I would have a Student class and a Course class. I should not have to create a StudentCourse class to link them. It's an artifact of my technology that does not have a parallel in the world I am trying to model.

In EF6.x this easy to set up using the Fluent API:

    modelBuilder.Entity<Student>()
                .HasMany<Course>(s => s.Courses)
                .WithMany(c => c.Students)
                .Map(cs =>
                        {
                            cs.MapLeftKey("StudentId");
                            cs.MapRightKey("CourseId");
                            cs.ToTable("StudentCourse");
                        });

zanate4019 avatar Jul 19 '18 13:07 zanate4019

Could U create ERD diagram with table relationship ? The Third table is need not for modern-fashionable style. 3 table is justified for perfomance and oprtimization purposes!

The current Firebird version database actually still read all record from Disk. 3-rd table this some kind compromise of perfomance vs comfortable usage!

In every RDMS will be perfomance degradation, if u're not using 3-rd table (wtih 2 foreign keys) !

Diaskhan avatar Jul 19 '18 13:07 Diaskhan

@zanate4019 to your question, the work item for this is https://github.com/aspnet/EntityFrameworkCore/issues/10508.

divega avatar Jul 22 '18 15:07 divega