2013-02-25 84 views
1

我有一段代码在LINQ查询子句:要选择凡使用功能

IList<Opportunity> filteredOpportunityProperties = new List<Opportunity>(); 
List<LookupWithIntId> selectedProperties = opportunityFilter.PropertyTypes; 
List<string> propertyTypes = selectedProperties.Select(item => item.Name).ToList(); 

opportunities.Where((item) => 
    { 
     string productType = item.Properties[0].ProductType; 
     bool propertyMatch = propertyTypes.Any(propTypes => productType.Contains(propTypes)); 
     if (propertyMatch) select item; 
    }); 

如果条件满足我想要的项目。但是,我收到错误:

Embedded statement cannot be a declaration or labeled statement

任何建议!

+0

哇,这太疯狂了!我不知道你可以用linq做到这一点! – 2013-02-25 00:08:44

回答

5

在你的where子句中,改变这一行:

if(propertyMatch) select item; 

要这样:

return propertyMatch; 

的地方,如果谓词结果为真子句将返回的项目,所以你只需要返回布尔结果。

+0

谢谢!这样可行。 – SaiBand 2013-02-25 00:27:20