I have a object:
public class Ticket
{
public string EventName {get;set;}
public string Count {get;set;}
public string Price {get;set;}
... other properties;
}
For test:
var tickets = new List<Ticket>();
tickets.Add(new Ticket {EventName = "Test", TicketCount = 1, Price = 100});
tickets.Add(new Ticket { EventName = "Test", TicketCount = 2, Price = 200 });
tickets.Add(new Ticket { EventName = "Test2", TicketCount = 1, Price = 50 });
I want to get anonymous object with following properties: EventName, TicketCount, Price
and "grouped" by event name.
For the example above the result must be:
anonymous object must contain two records:
EventName = Test, TicketCount = 3, Price = 300
EventName = Test2, TicketCount = 1, Price = 50
My not finished code:
var groupedByEvent = tickets.GroupBy(t => t.EventName);
var obj = new {EventName = seatsByEvent.Select(t=>t.Key), TicketCount = seatsByEvent.Sum(???)}
How to solve this?