Click here to Skip to main content
14,239,281 members
Rate this:
Please Sign up or sign in to vote.
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.

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 :)
Rate this:
Please Sign up or sign in to vote.

Solution 1

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[^]
   
v2
Comments
CrafterIt 1-Dec-11 7:09am
   
Thanks, i will look at it.
Rate this:
Please Sign up or sign in to vote.

Solution 2

   
Comments
CrafterIt 1-Dec-11 8:06am
   
Thanks this looks promising :)
Rate this:
Please Sign up or sign in to vote.

Solution 3

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[^]
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100