1

我的查询如下

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

linq中的等效查询是什么,请帮助我...

4

2 回答 2

0

试试这个,最好join在这种情况下使用 a 而不是子查询:

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()
于 2013-05-08T13:28:48.950 回答
0

或者,你可以使用这个:

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()

对我来说,它更清楚地显示了主查询和子查询。

归功于 @Bruno Brant 在Convert SQL Query (with Correlated Subquery) to LINQ in C#

于 2014-12-18T22:56:04.807 回答