Handle Many-to-Many Relationships in Entity Framework and ASP.NET MVC
Courtesy Peter Vogel, VisualStudioMagazine
It’s not unusual to have many-to-many relationships in an application. A recent project I worked on had multiple service technicians assigned to multiple locations, for instance. It’s also not unusual for there to be data that applies only to the relationship. In my client’s project, for example, at any location, a service technician has a specific position — and that position can be different from one location to another. (For instance, at one location, the tech might be the "responsible authority"; at another location, the tech might be the "support technician.") In addition, at each location, a tech is assigned a phone extension number where he can be reached.
In this column, I’ll work through this problem using Entity Framework Code First development, LINQ and (for the UI) ASP.NET MVC. By the end of the column you’ll have a roadmap for handling many-to-many relationships in your applications.