Click here to Skip to main content
15,920,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
var j=from o in Orders
join OT in OrderDetails on o.OrderId equals OT.OrderId
group OT.ProductId by o.OrderId into g
select new{OrderId=g.Key,ProductId=g};

The class Orders Contains TotalPrice. I want to retrieve it, but i get error,
I tried like this
var j=from o in Orders
join OT in OrderDetails on o.OrderId equals OT.OrderId
group OT.ProductId by o.OrderId into g
select new{OrderId=g.Key,ProductId=g,TotalPrice=o.TotalPrice};

It shows an error the term 'o' does not exist, pls help
Posted

1 solution

Hi
I am not sure if you want the total price for each order or if you want the sum of all the orders.

If you want the TotalPrice per row all you should need is:

var results = (from i in yourCollection
group g by i.Column into g
select new
{
ColumnName = o.Column,
ColumnTotal = o.Column,
}).ToList();

Else if you want the sum of all orders try:

var results = (from i in yourCollection
group g by i.Column into g
select new
{
ColumnName = i.Column,
ColumnTotal = i.Sum(x => x.Value)
}).ToList();

Let me know how you get on.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900