I would like to join the results of 2 entities based on the quantities. Here's what I have...
Order Ticket #1
OrderID CustomerID ItemID Description POS# Cost Quantity
1 1 1 Apples 111 1.25 3
1 1 2 Oranges 222 1.12 5
1 1 3 Bananas 333 1.17 5
Order Ticket #2
OrderID CustomerID ItemID Description POS# Cost Quantity
2 1 1 Apples 111 1.25 7
2 1 2 Oranges 222 1.12 2
2 1 3 Bananas 333 1.17 5
Here is the code I use to get each ticket:
public OrderEntity getOrder(int orderId)
{
var data = from c in Orders
where c.OrderID == orderId
select c;
return data;
}
How would I write the LINQ code to combine the 2 tickets so I get a Sum of the quantities? It should look like this...
Order Tickets #1 and #2
CustomerID ItemID Description POS# Cost Quantity
1 1 Apples 111 1.25 10
1 2 Oranges 222 1.12 7
1 3 Bananas 333 1.17 10
It seems like I should be able to do something like so...
public List<OrderEntity> getCustomerOrders(int customerId)
{
var data = from c in Orders
where c.CustomerID == customerId
select c;
return data.ToList();
}
The problem is I cannot figure out the grouping. There is a lot of info about there about how to write the EF code for grouping, but I'm not sure if I should be grouping on CustomerID or on the Quantity. Any tips on how to do the grouping here would be greatly appreciated.