C# 需要一个linq查询,其中包含指示属性匹配辅助列表中的所有值
我想在单个查询中复制以下逻辑C# 需要一个linq查询,其中包含指示属性匹配辅助列表中的所有值,c#,.net,linq,datatable,C#,.net,Linq,Datatable,我想在单个查询中复制以下逻辑 var currentRows = resultsTable.AsEnumerable(); foreach (var wholeWord in excludeWholeWords) { currentRows = from row in currentRows where !FoundWholeWord(wholeWord, row.Field<string>("busdescl")) select row;
var currentRows = resultsTable.AsEnumerable();
foreach (var wholeWord in excludeWholeWords)
{
currentRows = from row in currentRows
where !FoundWholeWord(wholeWord, row.Field<string>("busdescl"))
select row;
}
resultsTable = currentRows.CopyToDataTable();
var currentRows=resultsTable.AsEnumerable();
foreach(不包括wholewords中的var wholewords)
{
currentRows=来自currentRows中的行
where!FoundWholeWord(wholeWord,row.Field(“busdescl”))
选择行;
}
resultsTable=currentRows.CopyToDataTable();
我尝试了以下方法,但结果是匹配if!FoundWholeWords适用于任何WholeWords,而不是我的意图(即匹配意味着!FoundWholeWords适用于excludeWholeWords中的所有项目)
var matchGvRows = (from wholeWord in excludeWholeWords
from row in gvkeysTable.AsEnumerable()
where !FoundWholeWord(wholeWord, row.Field<string>("busdescl"))
select row).Distinct();
var matchGvRows=(来自excludeWholeWords中的WholeWords
来自gvkeysTable.AsEnumerable()中的行
where!FoundWholeWord(wholeWord,row.Field(“busdescl”))
选择行);
有什么想法吗?这个怎么样
var matchGvRows = excludeWholeWords.Aggregate(currentRows, (current, wholeWord) => current.Where(row => !FoundWholeWord(wholeWord, row.Field<string>("busdescl"))));
var matchGvRows=excludewwholewords.Aggregate(currentRows,(current,wholewords)=>current.Where(row=>!foundwholewords(wholewords,row.Field(“busdescl”));
这个怎么样
var matchGvRows = excludeWholeWords.Aggregate(currentRows, (current, wholeWord) => current.Where(row => !FoundWholeWord(wholeWord, row.Field<string>("busdescl"))));
var matchGvRows=excludewwholewords.Aggregate(currentRows,(current,wholewords)=>current.Where(row=>!foundwholewords(wholewords,row.Field(“busdescl”));
如果我正确理解了这个问题,应该是以下几点:
var newRows = currentRows
.Where(r => !excludeWholeWords.Any(w => w == r.Field<string>("busdescl"));
如果我理解正确的话,问题应该大致如下:
var newRows = currentRows
.Where(r => !excludeWholeWords.Any(w => w == r.Field<string>("busdescl"));
currentRows=excludeWholeWords.Aggregate(currentRows,(current,WholeWords)=>(来自当前行中的行
where!FoundWholeWord(wholeWord,row.Field(“busdescl”))
选择行);
这就是ReSharper的“转换为LINQ表达式”所做的。currentRows=excludeWholeWords.Aggregate(currentRows,(current,WholeWords)=>(来自current中的行
where!FoundWholeWord(wholeWord,row.Field(“busdescl”))
选择行);
这就是ReSharper的“Convert to LINQ expression”(转换为LINQ表达式)所做的。聚合按我的预期工作,但比@Klaus中的第二个示例花费的时间要长。聚合按我的预期工作,但比@Klaus中的第二个示例花费的时间要长。