I started using Entity Framework (Using POCO Classes) for a MVC 3 C# project with Razor Views.
I am having trouble implimenting the Many to Many features with it
I am trying to Create a View that when a User is able to add phone numbers, emails, musictypes, flags, holds, ntoes, etc… through Many to Many relationships
i.e.) Company —-> CompanyVenue <—- Venue
I have managed to get EF storing the Venue and then being able to asign the Venue afterwards by selecting the Venue in a list and assigning to to the Company.
Is there a way to get The Venue to automatically store the relationship from the Company to the Venue with out having to select it though a list?
If that is not possible can anyone share a better way of Implimenting using EF.
Just by having this simple setup:
EF should be able to determine that you’re declaring a many-to-many relation. I don’t know if you’re using EF 4.1 Code First or the model designer, but Code First should have enought with this to create the
CompanyVenuetable for you. And the model designer will define the “link” table for you as well as soon as you declare a many-to-many relation.Note that the navigation properties are marked as
virtual. This is necessary in the case of collections so that EF can make the proper updates in the related entities.