Entity Framework looking for wrong column
- by m.edmondson
I'm brand new to the Entity Framework and trying to learn all it can offer. I'm currently working my way through the MVC Music Store tutorial which includes the following code:
public ActionResult Browse(string genre)
{
// Retrieve Genre and its Associated Albums from database
var genreModel = storeDB.Genres.Include("Albums")
.Single(g => g.Name == genre);
return View(genreModel);
}
as I'm working in VB I converted it like so:
Function Browse(ByVal genre As String) As ActionResult
'Retrieve Genre and its Associated Albums from database
Dim genreModel = storeDB.Genres.Include("Albums"). _
Single(Function(g) g.Name = genre)
Return(View(genreModel))
End Function
The problem is I'm getting the following exception:
Invalid column name 'GenreGenreId'.
Which I know is true, but I can't for the life of my work out where it's getting 'GenreGenreId' from. Probably a basic question but I'll appreciate any help in the right direction.
As per requested here is the source for my classes:
Album.vb
Public Class Album
Private _title As String
Private _genre As Genre
Private _AlbumId As Int32
Private _GenreId As Int32
Private _ArtistId As Int32
Private _Price As Decimal
Private _AlbumArtUrl As String
Public Property Title As String
Get
Return _title
End Get
Set(ByVal value As String)
_title = value
End Set
End Property
Public Property AlbumId As Int16
Get
Return _AlbumId
End Get
Set(ByVal value As Int16)
_AlbumId = value
End Set
End Property
Public Property GenreId As Int16
Get
Return _GenreId
End Get
Set(ByVal value As Int16)
_GenreId = value
End Set
End Property
Public Property ArtistId As Int16
Get
Return _ArtistId
End Get
Set(ByVal value As Int16)
_ArtistId = value
End Set
End Property
Public Property AlbumArtUrl As String
Get
Return _AlbumArtUrl
End Get
Set(ByVal value As String)
_AlbumArtUrl = value
End Set
End Property
Public Property Price As Decimal
Get
Return _Price
End Get
Set(ByVal value As Decimal)
_Price = value
End Set
End Property
Public Property Genre As Genre
Get
Return _genre
End Get
Set(ByVal value As Genre)
_genre = value
End Set
End Property
End Class
Genre.vb
Public Class Genre
Dim _genreId As Int32
Dim _Name As String
Dim _Description As String
Dim _Albums As List(Of Album)
Public Property GenreId As Int32
Get
Return _genreId
End Get
Set(ByVal value As Int32)
_genreId = value
End Set
End Property
Public Property Name As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Public Property Description As String
Get
Return _Description
End Get
Set(ByVal value As String)
_Description = value
End Set
End Property
Public Property Albums As List(Of Album)
Get
Return _Albums
End Get
Set(ByVal value As List(Of Album))
_Albums = value
End Set
End Property
End Class
MusicStoreEntities.vb
Imports System.Data.Entity
Namespace MvcApplication1
Public Class MusicStoreEntities
Inherits DbContext
Public Property Albums As DbSet(Of Album)
Public Property Genres As DbSet(Of Genre)
End Class
End Namespace