Part 24 Entity for BridgeTable in many to many relationship

Thanks! Share it with your friends!

You disliked this video. Thanks for the feedback!

Added by tomm
4 Views
Text version of the video
http://csharp-video-tutorials.blogspot.com/2014/06/part-24-entity-for-bridgetable-in-many.html

Slides
http://csharp-video-tutorials.blogspot.com/2014/06/part-24-entity-for-bridgetable-in-many_11.html

Entity Framework - All Text Articles
http://csharp-video-tutorials.blogspot.com/2014/05/entity-framework-tutorial.html

Entity Framework - All Slides
http://csharp-video-tutorials.blogspot.com/2014/05/entity-framework-tutorial-slides.html

Entity Framework Playlist
https://www.youtube.com/playlist?list=PL6n9fhu94yhUPBSX-E2aJCnCR3-_6zBZx

Dot Net, SQL, Angular, JavaScript, jQuery and Bootstrap complete courses
https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd


In this video we will discuss a scenario in which Entity framework generates an Entity for the many-to-many relationship bridge table.

In Part 22 we used the following 3 tables. Notice that the Bridge Table (StudentCourses) does not have any additional columns except for the foreign keys (StudentID & CourseID). When an entity model was created based on these 3 tables, an entity for the bridge table is not generated.

Let us now, modify the Bridge Table (StudentCourses) to include EnrolledDate column.

Now if we generate an ADO.NET entity data model based on the above 3 tables, notice that 3 entities (Student, Course & StudentCourse) are generated. An entity (StudentCourse) for the bridge table (StudentCourses) is also generated.
a) Student entity has One-Many relationship with StudentCourse Entity
b) Course entity has One-Many relationship with StudentCourse Entity

Entity Framework interview question : Explain when an entity will and will not be created by the entity framework for the bridge table in a many-to-many relationship?
An entity for the bridge table is NOT created when the bridge table has only the foreign keys. On the other if the bridge table has any other columns apart from the foreign key columns then a bridge table is created.
Category
Relationship HOW TO

Post your comment

Comments

Be the first to comment