The entity framework is giving me some trouble.
Here are my tables:
Products
Related Products
And my DB context (part of it, anyway)...
ApplicationContext.cs
public class ApplicationContext : DbContext
{
public ApplicationContext() : base("DefaultConnection")
{
}
public DbSet<Product> Products { get; set; }
public DbSet<RelatedProduct> RelatedProducts { get; set; }
}
And the models...
Product.cs
public class Product
{
public int ID { get; set; }
public string Manufacturer { get; set; }
public string Model { get; set; }
public string PartNumber { get; set; }
public int CategoryID { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
public virtual ICollection<RelatedProduct> RelatedProducts { get; set; }
}
RelatedProduct.cs
public class RelatedProduct
{
public int ID { get; set; }
public int OwnerID { get; set; }
public int ProductID { get; set; }
public virtual Product Owner { get; set; }
public virtual Product Product { get; set; }
}
What I am trying to do
Loop through a list of related products like this:
<ul class="activity">
@foreach (var related in @Model.RelatedProducts)
{
<li>
<i class="fa fa-chevron-right red"></i> <strong>@related.Product.Manufacturer:</strong> @related.Product.Model
</li>
}
</ul>
The Problem
I keep getting this errorL
{"Invalid column name 'Product_ID'.\r\nInvalid column name 'Product_ID'.\r\nInvalid column name 'Product_ID'."}
Any ideas?