Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.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# 我应该使用什么来获取group by中的所有值,而不是FirstOrDefault()?_C#_Entity Framework_Linq_Asp.net Mvc 4 - Fatal编程技术网

C# 我应该使用什么来获取group by中的所有值,而不是FirstOrDefault()?

C# 我应该使用什么来获取group by中的所有值,而不是FirstOrDefault()?,c#,entity-framework,linq,asp.net-mvc-4,C#,Entity Framework,Linq,Asp.net Mvc 4,如何获取SpecificationDetails\u ID的所有值。通过下面的代码,我只需从一组值中获取第一个值。如何获取所有值 using(APM context=new APM()) { var lstprodspc = (from s in context.M_ProductSpecifaction //join p in context.M_SpecificationDetails on s.SpecificationDetails_ID equals p.ID

如何获取SpecificationDetails\u ID的所有值。通过下面的代码,我只需从一组值中获取第一个值。如何获取所有值

using(APM context=new APM())
{
      var  lstprodspc = (from s in context.M_ProductSpecifaction
    //join p in context.M_SpecificationDetails on s.SpecificationDetails_ID equals p.ID
    // join r in context.M_Specifications on p.Specification_ID equals r.ID
                          where s.Product_ID == P_ID
                          group s by s.Parent_ID into pg
                          select new 
                          {
                              ProductSD_ID = pg.FirstOrDefault().SpecificationDetails_ID 
                          }).ToList();
}


从上面的代码中,我只得到34,31,31,26,26,26,26。

您可以使用
选择
如下方式进行投影:-

 select new 
        {
           Parent_ID = pg.Key,
           ProductSD_ID = pg.Select(x => x.SpecificationDetails_ID).ToList()
        }).ToList();

您可以使用
选择
进行投影,如下所示:-

 select new 
        {
           Parent_ID = pg.Key,
           ProductSD_ID = pg.Select(x => x.SpecificationDetails_ID).ToList()
        }).ToList();