Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to convert this code into linq query.

The query below gives me to correct total in MS SQL.

SELECT SUM(t1.itemPrice + t2.itemPrice) as TOTAL_AMOUNT_DUE FROM table1 t1, table2 t2 WHERE r.userID = u.userID

I am trying to get this same code to work in linq query so I can use it in my project MVC4.

My attempt is failing mainly b/c I am not very familiar with Linq just yet. here it is:

--Linq--
var query = (from t1 in db.table1 join table2 in db.table2 on t1.userID equals t2.userID
select new { SUM(t2.itemPrice + t1.itemPrice) });

Obviously the above don't work. Can anyone help?

Thank you!

Ceci
Posted

1 solution

I think this should work
check for syntax errors if any
C#
(from p in table1
join q in table2 on p.userID equals q.userID
select p.itemPrice + q.itemPrice).ToList().Sum()
 
Share this answer
 
Comments
Member 273359 25-Sep-14 13:39pm    
that works. Thank you!
member33 25-Sep-14 13:41pm    
cool .could you mark it as accepted solution

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