Reputation: 2835
i am following Mvc MysicStore , Project . In my model class i have Genre.cs
namespace MvcMusicStore.Models
{
public class Genre
{
public int GenreId { get; set; }
public string Name { get; set; }
public string Descriptio { get; set; }
public List<Album> albums { get; set; }
}
}
and same way 2 more classes like Artis.cs Album,cs and Genre.cs .
Genre.cs
namespace MvcMusicStore.Models
{
public partial class Genre
{
public int GenreId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public List<Album> Albums { get; set; }
}
}
Album.cs
namespace MvcMusicStore.Models
{
public class Album
{
public int AlbumId { get; set; }
public int GenreId { get; set; }
public int ArtistId { get; set; }
public string Title { get; set; }
public decimal Price { get; set; }
public string AlbumUrl { get; set; }
public Genre genre { get; set; }
public Artist artist { get; set; }
}
}
My problem is that when i try to use these classes with sample data it says
i have made sure there are no namespace issues and i have created a class SampleData.cs that has following code that gives error
new List<Album>
{
new Album { Title = "The Best Of Men At Work",
Genre = genres.Single(g => g.Name == "Rock"),
Price = 8.99M, Artist = artists.Single(a => a.Name == "Men At Work")
, AlbumArtUrl = "/Content/Images/placeholder.gif" },
it shows me above mentioned error for this code whats wrong with it ?
Upvotes: 0
Views: 102
Reputation: 4040
I think your property is written in lowercase and you try to access it as Genre
. Try renaming it.
It's because your Album
class doesn't have a Genre
property, but a genre
property.
Instead of
public Genre genre { get; set; }
try
public Genre Genre { get; set; }
Upvotes: 2