Reputation: 3914
As the title indicates I am looking for the solution to this with the Association attribute also the property for the EntitySet<> setter since it differs for the Many To Many relationship I am not sure I am going in the right direction with since there are no examples of said relationship, due to L2S being very difficult with this type of relation.
Does the Foreign Key table have to have references or sets to the 2 tables that it joins...?
Example:
Do I use a many to many in this case? or would I better off refactoring to a one to many?
Upvotes: 2
Views: 455
Reputation: 2129
If the foreign key relationships exists in SQL, L2S will have both the properties (ex HotelId, ScheduledFlightId) and the EntityRefs in the HotelToScheduledFlights table object. Hotels will then have an EntitySet pointing to HotelToScheduledFlights as will ScheduledFlights.
I think that this is a valid many to many relationship, so long as you are planning on needing to find hotels by flight and flights by hotel.
To get all of the flights tied to a hotel you would do:
Hotel h = dc.Hotels.First(); // Pick a hotel
List<ScheduledFlight> l = h.HotelToScheduledFlight.Select(i => i.ScheduledFlight).ToList();
Upvotes: 1