将T-SQL命令转换为Lambda表达式

时间:2018-12-15 15:39:27

标签: sql linq lambda

请帮助我将以下命令转换为等效的lambda

Select t1.id, t1.fullname 
From t1 
Where t1.id in (Select t2.id From t2 Where t2.bNo = 5))

2 个答案:

答案 0 :(得分:0)

您可以尝试将linq whereAny一起使用。

var result = t1.Where(x => t2.Any(x1 => x1.Id == x.Id && x1.bNo == 5))
                  .Select(x => new { x.Id, x.fullName });

c# online

答案 1 :(得分:0)

您可以在表达式中尝试contains

var IdListQuery = context.t2.where(c=> c.bNo == 5).select(s=> s.id);
var query = context.t1.where(c=>IdListQuery.contains(c.id)).select(s=> s.id, s.fullname);