我的查询如下
`Select * from daps_user_activity where Userid In (Select Userid from daps_portaluser where EMR_ID = 24855) `
linq中的等效查询是什么,请帮助我...
试试这个,最好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()
或者,你可以使用这个:
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#