我有以下Transact-Sql,我正尝试将其转换为LINQ ...并正在挣扎。

SELECT * FROM Project
WHERE Project.ProjectId IN (SELECT ProjectId FROM ProjectMember Where MemberId = 'a45bd16d-9be0-421b-b5bf-143d334c8155')

任何帮助将不胜感激...如果可能的话,我想使用Lambda表达式来做。

提前致谢!

最佳答案

GFrizzle击败了我。但是这是一个C#版本

var projectsMemberWorkedOn = from p in Projects
                    join projectMember in ProjectMembers on
                        p.ProjectId equals projectMember.ProjectId
                    where projectMember.MemberId == "a45bd16d-9be0-421b-b5bf-143d334c8155"
                    select p;

作为奖励,还有纯LINQ方法链版本:
var projectsMemberWorkedOn =
            Projects.Join( ProjectMembers, p => p.ProjectId, projectMember => projectMember.ProjectId,
                ( p, projectMember ) => new { p, projectMember } )
                .Where( @t => @t.projectMember.MemberId == "a45bd16d-9be0-421b-b5bf-143d334c8155" )
                .Select(@t => @t.p );

关于sql - 如何使用LAMBDA表达式在LINQ中进行IN或CONTAINS处理?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/351840/

10-08 21:10