I´m having trouble understand EF.
I have 2 tables in a N-to-N relationship. When I create the model in Visual Studio I get it like the picture below. Artist is related to Album, and Album is related to Artist. In the database I have a table to relate both tables.My question is:
Why can I add an artist with two albums,
var artist = new Artist { FirstName = "Alan", LastName = "Jackson" };
var album1 = new Album { AlbumName = "Drive" };
var album2 = new Album { AlbumName = "Live at Texas Stadium" };
artist.Albums.Add(album1);
artist.Albums.Add(album2);
context.Artists.Add(artist);
But can´t do the other way around?
var artist1 = new Artist { FirstName = "Tobby", LastName = "Keith" };
var artist2 = new Artist { FirstName = "Merle", LastName = "Haggard" };
var album = new Album { AlbumName = "Honkytonk University" };
artist1.Albums.Add(album);
artist2.Albums.Add(album);
context.Albums.Add(album);
context.SaveChanges();
It´s not making sense to me, since both tables in VS model have the Navigation Properties correct, isn´t the same adding to left or right? In my mind, in the second case EF should add artist1 and artist2 to DB.
Thanks for reading. FranciscoRC