ASP.NET MVC:如何使用包含标签
任何身体都可以解释如何使用包括()吗?我看到我们在模型中列出了HAE图像列表,是否将它们包含在DB中?
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();
}
产品模型
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; }
Can any body explain how to use Include()? I see we hae Images list in model, is it nessesary ti include them in db?
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();
}
Product 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; }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
包括在此处完成的是填写
list&lt; prodimage&gt;图像
,带有链接到产品的外键的图像。否则此列表将为空。不需要。如果要使用这些图像,则应包括它们。
What Include would do here, is fill the
List<ProdImage> Images
, with the images that have a foreign key linking to the product. Otherwise this list would be empty.It is not required. If you want to use those images, then you should include them.