2015-11-04 56 views
0

如何获得SpecificationDetails_ID的所有值。通过下面的代码,我只是从第一组值中获取第一个值。获取所有值的方法是什么?而不是FirstOrDefault()我用什么来获取组中的所有值?

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(); 
} 

Here attaching the image of table values :

enter image description here

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

回答

2

可以使用Select喜欢这个项目吧: -

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