Lesson 4 MvcMusicStore- Not Step by Step project -WHERE DID THIS SampleData.cs come from? How exactly was this file created?

Jun 10, 2012 at 4:35 PM

WHERE DID THIS SampleData.cs  come from? How exactly was this file created?
I thought this artcle was a step by step direction.
Just magically addinfg a file  out of thin air and placing it in the  project now stepping through how the file was created is not step by step.

Coordinator
Jun 12, 2012 at 7:03 AM

@stevensrf1 This is sample data. The tutorial shows how to add albums one at a time to the database, but adding hundreds of albums, artists, and songs one at a time isn't the point of the tutorial. You can read more about database initializers in this MSDN Magazine article: http://msdn.microsoft.com/en-us/magazine/hh126815.aspx

If you look at the SampleData.cs class, you'll see that it just inserts a bunch of sample data, like this:

var genres = new List<Genre>
{
	new Genre { Name = "Rock" },
	new Genre { Name = "Jazz" },
	new Genre { Name = "Metal" },
	new Genre { Name = "Alternative" },
	new Genre { Name = "Disco" },
	new Genre { Name = "Blues" },
	new Genre { Name = "Latin" },
	new Genre { Name = "Reggae" },
	new Genre { Name = "Pop" },
	new Genre { Name = "Classical" }
};

genres.ForEach(s => context.Genres.Add(s));
context.SaveChanges();