ASP.NET MVC:如何使用包含标签

发布于 2025-02-10 02:07:00 字数 758 浏览 2 评论 0原文

任何身体都可以解释如何使用包括()吗?我看到我们在模型中列出了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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒浓于脸红 2025-02-17 02:07:00

包括在此处完成的是填写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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文