Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# LINQ-ENTITY:需要返回另一个表中的行数列表_C#_Mysql_Linq_Entity Framework - Fatal编程技术网

C# LINQ-ENTITY:需要返回另一个表中的行数列表

C# LINQ-ENTITY:需要返回另一个表中的行数列表,c#,mysql,linq,entity-framework,C#,Mysql,Linq,Entity Framework,我有一个表产品和故障系统。每个产品都可能有许多故障。故障表有一个外键ProductID。我需要一份大约十种故障最多的产品的清单。我尝试了以下方法,但似乎没有效果。我需要的字段是产品名称、价格、id和故障数: return (from p in Entity.Products join f in Entity.Faults on p.ProductID equals f.ProductID

我有一个表产品和故障系统。每个产品都可能有许多故障。故障表有一个外键ProductID。我需要一份大约十种故障最多的产品的清单。我尝试了以下方法,但似乎没有效果。我需要的字段是产品名称、价格、id和故障数:

      return (from p in Entity.Products
                join f in Entity.Faults
                on p.ProductID equals f.ProductID
                group f by new { f.ProductID, p.Name, p.Price } into product
                select new CountFaultView()
                {
                    ProductID = product.Key.ProductID,
                    Name = product.Key.Name,
                    Price = product.Key.Price,
                    FaultsCount = product.Key.Name.Count()
                }
                ).OrderByDescending(x => x.FaultsCount).Take(10);

    }

我试图数一数这个名字被显示的次数,但很明显我似乎有点不对劲;o

你能公布你得到的结果吗?另外,您是否尝试返回“产品”以查看其是否工作,然后尝试投影到CountFaultView。结果为空,我将尝试使用productTry FaultsCount=product.CountWorks这样的产品,谢谢!