如何将以下内容转换为LINQ查询或对象查询?
SELECT ABC FROM dbo.TableOne
WHERE XID IN (SELECT YID FROM dbo.TableTwo
WHERE YId = 1 AND ZID2 = 2)
答案 0 :(得分:1)
以下内容应该有效。我没有编译它,所以纠正语法错误,如果有的话。
此外,您应该先自己尝试这些事情然后发布。
from tab1 in TableOne
where
(
from xyz in TableTwo
where xyz.YId == 1 && xyz.ZID2 == 2
select xyz.YID
).Contains(tab1.XID)
select new { tab1.abc }
或EF
var arrYID = (from xyz in TableTwo
where xyz.YId == 1 && xyz.ZID2 == 2
select xyz.YID).ToArray();
var objABC = from tab1 in TableOne
where arrYID.Contains(tab1.XID).select new {tab1.abc};