1

My Query as Follows

   `Select * from daps_user_activity where Userid In (Select Userid from daps_portaluser  where EMR_ID = 24855) `

What is the equivalent query in linq please help me...

Muralikrishna
  • 245
  • 1
  • 4
  • 15
  • It will be much easier if you revise your original query to JOIN the two tables instead of using a subquery. – DOK May 08 '13 at 13:25
  • Check this link http://stackoverflow.com/questions/51339/how-can-you-handle-an-in-sub-query-with-linq-to-sql – Shailesh May 08 '13 at 13:28

2 Answers2

0

Try this, it's better that you use a join in this instance, instead of a sub-query:

var results = (from a in daps_user_activity
              join u in daps_portaluser on a.Userid equals u.Userid
              where u.EMR_ID == 24855
              select a).ToList()
Mathew Thompson
  • 55,877
  • 15
  • 127
  • 148
0

Alternatively, you could use this:

var results = (from a in daps_user_activity
               from u in daps_portaluser
               where u.EMR_ID == 24855 
               && a.Userid == u.Userid
               select a).ToList()

To me, it shows more clearly the main query and the subquery.

Credit goes to @Bruno Brant at Convert SQL Query (with Correlated Subquery) to LINQ in C#

Community
  • 1
  • 1
user8128167
  • 6,929
  • 6
  • 66
  • 79