将子查询SQL与LINQ相关联 [英] Correlated SubQuery SQL to LINQ

查看:69
本文介绍了将子查询SQL与LINQ相关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

select * 
  from Table1 
 where TC in (select TC 
                from Table2 
               where Application in ('AAA'))`

帮助我将上述查询转换为LINQ.

help me in converting above query to LINQ.

推荐答案

没有where Application in ('AAA')部分,这看起来很简单:

Without where Application in ('AAA') part this looks quite simple:

from t1 in db.Table1s
where db.Table2s.Select(t2 => t2.TC).Contains(t1.TC)
from t1 in db.Table1s

更新(我错了!)

List<string> myCollection = new List<string> { "AAA" };
from t1 in db.Table1s
where db.Table2s.Where(t2 => myCollection.Contains(t2.Application)).Select(t2 => t2.TC).Contains(t1.TC)
from t1 in db.Table1s

应该与代码内集合一起使用.

should work with in-code collections.

这篇关于将子查询SQL与LINQ相关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆