What is the LINQ equivalent of
SELECT primaryID, name, description, unit, SUM(price)
FROM Product
JOIN so that same Products are returned multiple times
GROUP BY primaryID
I know that it is possible to make groupBy queries using LINQ, like this:
(from item in dbContext.products
join some join statement that will make products return multiple times
group item by item.primaryID into g
select new {id = key, summedPrice = g.Sum(x => x.price)}
)
But this way, i only get the ID and the aggregate. How do i get the other fields aswell?
I guess i could make my key a annon class that has all the columns i need, but i'm note sure if that would impact perfarmance, like this:
group item by new { item.primaryID, item.name, item.description...} into g