如何获取SpecificationDetails_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,31,26,26,26,26。
答案 0 :(得分:3)
您可以使用Select
进行投影,如下所示: -
select new
{
Parent_ID = pg.Key,
ProductSD_ID = pg.Select(x => x.SpecificationDetails_ID).ToList()
}).ToList();