sql – 如何使用LAMBDA表达式在LINQ中进行IN或CONTAINS?

前端之家收集整理的这篇文章主要介绍了sql – 如何使用LAMBDA表达式在LINQ中进行IN或CONTAINS?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下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 );
原文链接:https://www.f2er.com/mssql/76612.html

猜你在找的MsSQL相关文章