【问题标题】:asp.net MVC how to show chlid count of modelasp.net MVC如何显示模型的子数
【发布时间】:2016-01-16 10:45:40
【问题描述】:

我有一个名为 ProductGroup 的模型,我想显示视图中任何产品组的子项数。

【问题讨论】:

  • 发布您的代码,而不是它的图像。并展示您尝试过的内容。
  • 在 ProductGroup 列表上循环并执行 pg.Products.Count 有什么问题?

标签: c# asp.net asp.net-mvc entity-framework-6


【解决方案1】:

这是一个非常简单的 LINQ 查询:

var productChildCounts = context.ProductGroups
                .Include(pg => pg.Products)
                .Include(pg => pg.Attributes)
                .Select(pg => new
                {
                    pg.Title,
                    ProductCount = pg.Products.Count(),
                    AttributeCount = pg.Attributes.Count()
                });

http://www.dotnetcurry.com/ShowArticle.aspx?ID=513

【讨论】:

    猜你喜欢
    • 2013-07-30
    • 2021-08-14
    • 1970-01-01
    • 2010-12-21
    • 1970-01-01
    • 2011-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多