Can Entity Framework handle many to many relationship without an intersection object?

后端 未结 2 383
有刺的猬
有刺的猬 2021-01-11 23:30

Using database first model: Let\'s say we have the classic tables Student, Course and StudentCourse (the latter obviously having FKs t

2条回答
  •  旧巷少年郎
    2021-01-11 23:47

    According to this tutorial, you'll get the desired behaviour if your StudentCourse table only contains the foreign-key columns. If it contains any other columns, EF will generate an intermediate entity to represent the join.

    In this case, dropping the surrogate key from the StudentCourse table and replacing it with a composite primary key should work.

提交回复
热议问题