[英]Where clause in LINQ query using a function
I have a piece of code: 我有一段代码:
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;
});
if the condition matches I want that item to be selected. 如果条件匹配,我希望选择该项目。 However, I get the error:
但是,我得到了错误:
Embedded statement cannot be a declaration or labeled statement
嵌入式语句不能是声明或带标签的语句
Any suggestions! 有什么建议么!
In your where clause, change this line: 在您的where子句中,更改以下行:
if(propertyMatch) select item;
To this: 对此:
return propertyMatch;
The where clause will return the item if the predicate result is true, so you just need to return the boolean result. 如果谓词结果为true,则where子句将返回该项,因此您只需要返回布尔结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.