Question: My SQL designer is off currently, and i need to get some (What i assumed was simple) LINQ done, I've never gotten round to learning this stuff, but I thought it would be simple enough, he even left me some SQL code for an example, but all my efforts have failed.

What I'm trying to do is such:

I have a list of `OrderedItem` Objects, these contain an `ItemName`, `quantity` and `PPU`.

I want to generate a second list from this, with only distinct `ItemNames`, total for `quantity` of all those orderditems with that `ItemName`, and max for `PPU`.

To clear that up here is the SQL I was left.

```
Select ItemName
       SUM(Quantity)
       MAX(PPU)
FROM ..... (my list)
Group By ItemName

```

I would appreciate any help in getting a LINQ version of this.

Answer: 
```
var query = from rec in dbo.TableName
            group rec by rec.ItemName into ItemNameGroup
            select new { 
                ItemName = ItemNameGroup.Key, 
                SumQuantity = ItemNameGroup.Sum(r => r.Quantity),
                MaxPPU = ItemNameGroup.Max(r => r.PPU)
            };

```
I assume your class is:

```
class OrderedItem
{
    public string ItemName { get; set; }
    public decimal Quantity { get; set; }
    public int PPU { get; set; }
}

```

Then you can write the following LINQ query with extension methods:

```
var objects = new List<OrderedItem>();
objects.GroupBy(x => x.ItemName).Select(x => new
{
    ItemName = x.Key,
    Quantity = x.Sum(y => y.Quantity),
    PPU = x.Max(y => y.PPU)
});

```