LINQ:"包含"和LAMBDA查询 [英] LINQ: "contains" and a Lambda query

查看:124
本文介绍了LINQ:"包含"和LAMBDA查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含枚举,其标准的枚举,但有连接到它并返回枚举的CHAR扩展方法的属性列表(见下文 - GetCharValue),扩展的伟大工程

I have a list which contains enums, its a standard Enum but has an attribute attached to it and an extension method which returns a CHAR of the enum (see below - GetCharValue), the extension works great.

现在我(对LINQ另一种扩展方法)

Now I have (another extension method for linq)

public static IQueryable<Building> WithStatus(this IQueryable<Building> qry, 
         IList<BuildingStatuses> buildingStatus)
{
    return from v in qry
           where buildingStatus.Where(item => item.GetCharValue() == 
           v.Status)
           select v;
}

基本上,我需要说的回归一切都在查询,但只有当v.Status是buildingStatus ......但记得buildingStatus是枚举一个IList,所以我的必须的调用GetCharValue。

I basically need to say "Return" everything in query but only if v.Status is in buildingStatus... but remember buildingStatus is an ILIST of enums so I MUST call GetCharValue.

我有一些帮助previously了我认为正确的语法是

I had some help previously had i think the correct syntax is

buildingStatus.Contains (v.Status)   

但问题是这里buildingStatus是枚举的IList的所以才说我必须调用GetCharValue()在IList中每个项目包含..

but the problem is here that buildingStatus is a Ilist of Enums so i must call GetCharValue() on each Item in the Ilist before saying Contains..

我在想有什么用使用lambda这样的特殊方式包含像这样 - 当然,这是行不通的。

I was thinking there was something special way of doing this with lambda using Contains like so - of course it doesn't work

where buildingStatus.Contains(item => item.GetCharValue() == v.Status)

谁能帮助?

推荐答案

使用 任何() 而不是包含:

buildingStatus.Any(item => item.GetCharValue() == v.Status)

这篇关于LINQ:&QUOT;包含&QUOT;和LAMBDA查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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