C# 表达式中的交叉引用集合<;Func<&燃气轮机&燃气轮机;

C# 表达式中的交叉引用集合<;Func<&燃气轮机&燃气轮机;,c#,linq,entity-framework,C#,Linq,Entity Framework,我在LINQtoEntities查询中使用以下表达式 private Expression<Func<PageElement, bool>> ViewerProfileCheckExp(IViewerProfileModel vpSource) { return (pe) => pe.ViewerProfiles.Any(vp => vp.ViewLevel.Id == vpSource.ViewLevelId &&

我在LINQtoEntities查询中使用以下表达式

private Expression<Func<PageElement, bool>> ViewerProfileCheckExp(IViewerProfileModel vpSource)
    {
        return (pe) => pe.ViewerProfiles.Any(vp => vp.ViewLevel.Id == vpSource.ViewLevelId &&
                                                        vp.ViewTransitId == vpSource.ViewTransitId &&
                                                        vp.ViewGroups.ContainsAny(vpSource.Groups));
    }
private Expression ViewerProfileCheckExp(IViewerProfileModel vpSource)
{
return(pe)=>pe.ViewerProfiles.Any(vp=>vp.ViewLevel.Id==vpSource.ViewLevelId&&
vp.viewtrantid==vpSource.viewtrantid&&
ViewGroups.ContainsAny(vpSource.Groups));
}

在最后一个子句中,如果vp中的任何ViewGroup包含在vpSource.Groups中,我希望能够在条件中返回true。我意识到ContainsAny不存在,但我想知道如何将我想要的内容集成到表达式中。

您在逻辑上寻找的是两个集合的交集是否有任何项:

vp.ViewGroups.Intersect(vpSource.Groups).Any()

您在逻辑上寻找的是两个集合的交集是否有任何项:

vp.ViewGroups.Intersect(vpSource.Groups).Any()