[英]ASP.NET MVC: how to use Include tag
任何人都可以解釋如何使用 Include() 嗎? 我看到我們在 model 中有圖像列表,是否必須將它們包含在數據庫中?
public IEnumerable<Product> GetAll(int Productstate)
{
return db.Products.Include("Tags").Include("Images").Include("Category").Include("Format").Where(pl => pl.state > 0).Where(p=>p.state >= Productstate);
}
public Product Get(Int64 id)
{
return db.Products.Include("Images").Include("Category").Where(PPR => PPR.Id == id).FirstOrDefault();
}
產品 model
public Int64 Id { get; set; }
public List<ProdImage> Images { get; set; }
[MaxLength(20)]
public String Color { get; set; }
public Int64 CustomPropertyId { get; set; }
public DateTime CreateTime { get; set; }
Include 在這里要做的是填充List<ProdImage> Images
,其中的圖像具有鏈接到產品的外鍵。 否則此列表將為空。
這不是必需的。 如果你想使用這些圖像,那么你應該包括它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.