Part 25 Entity for BridgeTable in many to many relationship code first HD
Link for all dot net and sql server video tutorial playlists http://www.youtube.com/user/kudvenkat/playlists Link for slides, code samples and text version of the video http://csharp-video-tutorials.blogspot.com/2014/06/part-25-entity-for-bridgetable-in-many_12.html In this video we will discuss creating an Entity for the bridge table in a many-to-many relationship with code first. This is continuation to Part 24. Please watch Part 24 before proceeding. We want the entity framework to create the following tables. 1. Courses - CourseID should be the Primary Key 2. Students - StudentID should be the Primary Key 3. StudentCourses - Composite primary key consisiting of CourseID & StudentID columns. CourseID should also be the foreign key referencing CourseID column in Courses table. StudentID should also be the foreign key referencing StudentID column in Students table. To achieve this we would design Student, Course & StudentCourse classes as shown below. public class Course { public int CourseID { get; set; } public string CourseName { get; set; } public IList[StudentCourse] StudentCourses { get; set; } } public class Student { public int StudentID { get; set; } public string StudentName { get; set; } public IList[StudentCourse] StudentCourses { get; set; } } public class StudentCourse { public Course Course { get; set; } public Student Student { get; set; } [Key, Column(Order = 1)] public int StudentID { get; set; } [Key, Column(Order = 2)] public int CourseID { get; set; } public DateTime EnrolledDate { get; set; } }
Похожие видео
Показать еще