I am following the ASP MVC 3 music store tutorial–translating the C# into VB.
http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-4
I have a class called SampleData that is supposed to hold the data for the application. It looks like this:
Public Class SampleData
Inherits DropCreateDatabaseIfModelChanges(Of MusicStoreEntities)
Protected Overrides Sub Seed(context As MusicStoreEntities)
Dim genres As Genre() = { _
New Genre() With {.name = "Rock"},
New Genre() With {.name = "Jazz"},
... more genres...
}
I have a class called MusicStoreEntities that inherits from DbContext like this:
Public Class MusicStoreEntities
Inherits DbContext
Property albums As DbSet(Of Album)
Property genres As DbSet(Of Genre)
My controller is supposed to return a view that lists the genres but the list of genres is empty.
' GET: /Store
Dim storeDB As MusicStoreEntities = New MusicStoreEntities()
Function Index() As ActionResult
Dim genres As List(Of Genre) = storeDB.genres.ToList
Return View(genres)
End Function
I am also calling my seed in Application_start, located in global.asax
Sub Application_Start()
System.Data.Entity.Database.SetInitializer(
New MvcMusicStore.Models.SampleData())
Basically, I should see all of the genres but don’t.
I have no idea how to go about debugging. Where do I start?
Are you calling your seed in your Application_start, located in global.asax?
I don’t know vb but here’s the c#:
Altering
DropCreateDatabaseIfModelChangestoDropCreateDatabaseAlwayscould also help, it will force your database to drop and reseed every time the program is run.