I have a SubCategory model in an mvc 4 application for a shirt shop and I am wanting to populate the database using seed data when I ran my application, I recieve Error Message: "Sequence Contains no matching elements"
My code:
var subCategories = new List<SubCategory>
{
new SubCategory{Category = categories.Single(s => s.Name == "Animals") , Name "Animal Prints"},
new SubCategory{Category = categories.Single(s => s.Name == "Animals") , Name = "Bugs"},
};
The reason is that you don't have any entry in you categories with name as "Animals" if you wanted to check it
var categorie = categories.where(s => s.Name == "Animals").SingleOrDefault();
if(categories == null)
{
// db is not seeded with categories do something
}
else
{
var subCategories = new List<SubCategory>
{
new SubCategory{Category = categorie , Name "Animal Prints"},
new SubCategory{Category = categorie , Name = "Bugs"},
};
}