2013-02-25 82 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