我正在尝试使用 EF 映射一对多关系,但由于某种原因,这比平常更困难。这是我的 EDMX 和 DB 架构。我在中间表上使用自动增量键的原因是因为我被告知在 EF 中使用复合键很困难。
我需要的是能够(使用类(class)实体)someCourse.Students 或(使用学生实体)someStudent.Courses。谁能给我一些关于映射此图的最佳方法的指示?
alt text http://img195.imageshack.us/img195/4053/schemacz.png alt text http://img22.imageshack.us/img22/8193/edmx.png
最佳答案
如果删除 AssociationID 列并将 StudentID 和 CourseID 都设置为 StudentCourses 表的主键,它将拾取多对多关系并生成更直观的实体类(即 Student.Courses、Course.Students) )
关于c# - Entity Framework : One<->Many<->One Mapping?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1755279/