I have 3 tables. One called Artist, One called Song and one called Album.
Artist is linked to song as 1 to many. Artist is also linked to Album as 1 to many. Song is linked to Album as many to many so a bridge table was automatically created. The song table has a navigation property of artist and album and the album has a navigation property of Artist and song. I want to add a new song. When adding a song the bridge table doesn't get updated so I want to know how I can reference the album that is associated with the song when adding it.
public int CreateNewSong(String name,String songTitle)
{
using(var context = new Myentities())
{
Song theNewSong = new Song()
Artist refer = context.Artists.Single(o => o.ArtistName == name);
theNewSong.SongTitle = songTitle;
theNewSong.Artist_ArtistID = refer.ArtistID;
context.Songs.AddObject(theNewSong);
context.SaveChanges();
return theNewSong.SongID;
}
}