I've tried to solve this fro quite some time already with no luck, guessing it will be a doddle for someone with experience. I'm using the MvcMusicStore.
I have a db context and I have added a new album with a new Genre. If I want to add another album with the same Genre, how do I assign the existing Genre to the new album? As in the second album below. Thanks in advance for any help.
protected override void Seed(Models.MusicStoreDBContext context)
{
context.Artists.Add(new Models.Artist { Name = "Al Di Meola" });
context.Genres.Add(new Models.Genre { Name = "Jazz" });
context.Albums.Add(new Models.Album
{
Artist = new Models.Artist { Name = "Sublime" },
Genre = new Models.Genre { Name = "Rock" },
Price = 11.99m,
Title = "40oz to Freedom"
});
context.Albums.Add(new Models.Album
{
Artist = new Models.Artist { Name = "Jawbox" },
Genre = "Rock", // HOW DO I ASSIGN THIS?
Price = 10.99m,
Title = "For your own special sweetheart"
});