Click here to Skip to main content
15,905,612 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!

I'm not that familiar with Linq and lambda.
I have this SQL statement that i want to translate into a Linq or Lamda expression.

SQL
Select A, C, D, Count(D) AS ‘E’ FROM TABLE
WHERE C = 2 AND D = 4 
GROUP BY A, C, D


Can someone help me translate this into Linq or Lambda?

Thanks!
Posted
Updated 1-Dec-11 2:01am
v3
Comments
Amir Mahfoozi 1-Dec-11 6:33am    
Are you sure that this is a correct SQL statement ?
CrafterIt 1-Dec-11 7:06am    
No sorry, forgot to add group by A, C, D
Amir Mahfoozi 1-Dec-11 7:41am    
It still looks incorrect to me :) there should be a comma between d and count(d)
CrafterIt 1-Dec-11 8:05am    
you are right, forgot that too :)

This is just an example don't know the run time results::

var z = from x in Table
where x.c = 2 and d = 4
select  A = x.a, B = x.b ,D =x.d , E = x.D.Count()


But you can get idea from this

You also can take help from this link

How To: LINQ To SQL Transformations - Part II[^]
 
Share this answer
 
v2
Comments
CrafterIt 1-Dec-11 7:09am    
Thanks, i will look at it.
 
Share this answer
 
Comments
CrafterIt 1-Dec-11 8:06am    
Thanks this looks promising :)
SQL
here i am posting some thing about Linq basic operation select, insert, delete, update.



http://suhasharidas.blogspot.in/2012/08/create-linq-to-sql-connection-with.html[^]
 
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