2つのテーブルを含むデータベースがあります
TABLE Categories (CategoriesId, Name, Description)
TABLE Products (ProductId, CategoriesId, Title, ProductImageUrl)
カテゴリは、CategoriesIdによって製品にリンクされています。
LINQを使用して特定のタイトルをすべて取得しようとしています。
public ActionResult Browse(string categories)
{
var spices = spiceDB.Products.Include("Products").Single(p => p.Title == categories);
return View(spices);
}
製品モデル
namespace SpiceShop.Models
{
public class Product
{
[Key]
public int ProductId { get; set; }
public int CategoriesId { get; set; }
public string Title { get; set; }
public string ProductImageUrl { get; set; }
public List <Categorie> Name { get; set; }
}
}
カテゴリモデル
namespace SpiceShop.Models
{
public class Categorie
{
[Key]
public int CategoriesId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
//public List<Product> ProductId { get; set; }
public List<Product> Products { get; set; }
}
}