本文介绍了如何将以下转换成LINQ查询或对象查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将以下内容转换为LINQ查询或对象查询?

How to convert following into LINQ query or Object Query?

 SELECT ABC FROM dbo.TableOne
 WHERE XID IN (SELECT YID FROM dbo.TableTwo
 WHERE YId = 1 AND ZID2 = 2)


推荐答案

以下内容应该有效。我没有编译它如此正确的语法错误,如果有的话。

The following should work. I have not compiled it so correct the syntax errors if any.

此外,你应该首先尝试这些事情,然后发布。

Also you should try these things by yourself first and then post.

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};

这篇关于如何将以下转换成LINQ查询或对象查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 04:28