Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从LINQ查询中选择列,其中单元格等于列表中的值_C#_Linq_Compare_Observablecollection - Fatal编程技术网

C# 从LINQ查询中选择列,其中单元格等于列表中的值

C# 从LINQ查询中选择列,其中单元格等于列表中的值,c#,linq,compare,observablecollection,C#,Linq,Compare,Observablecollection,我从LINQ查询向ObservableCollection添加了数据: foreach (var item in test4) { lstPareto.Add(new clsPareto(Convert.ToInt32(item.Step), Convert.ToInt32(item.LogID), test3.Where(p => p.Step.Equals(item.Step) && p.LogID.Equals(item.LogID)).Count())); }

我从LINQ查询向ObservableCollection添加了数据:

foreach (var item in test4)
{
   lstPareto.Add(new clsPareto(Convert.ToInt32(item.Step), Convert.ToInt32(item.LogID), test3.Where(p => p.Step.Equals(item.Step) && p.LogID.Equals(item.LogID)).Count()));
}
这个很好用。我得到我想要的项目,并在将它们添加到列表时将它们转换为int

然后我有以下从多个数据库提取数据的查询:

int intCmbTestNr = Convert.ToInt32(m_strCmbTestNrSelectedItem);

var productIndex = (from x in m_dcSQL_ConnectionProdTest.DC3_VersionReleases
                    where x.TestNumber.Equals(intCmbTestNr)
                    select x.ProductIndex).First();

var version = ((from y in m_dcSQL_ConnectionProdTest.DC3_MainSetups
                where y.ProductIndex == productIndex && y.SubVersion == 0
                select y.Version).Max());

var versionIndex = (from z in m_dcSQL_ConnectionProdTest.DC3_MainSetups
                    where z.ProductIndex == productIndex && z.Version.Equals(version) && z.SubVersion == 0
                    select z.VersionIndex).First();

var subFuncName = from a in m_dcSQL_ConnectionProdTest.DC3_SubFunctions
                  where a.VersionIndex == versionIndex && a.FunctionNumber == lstPareto.Select(b => b.intStep) && a.SubFunctionNumber == lstPareto.Select(c => c.intStep)
                  select a.SubFunctionName;
考虑子函数名。我在这里试图实现的是将a.FunctionNumber与列表lstPareto的intStep和a.SubFunctionNumber与intLogID进行比较。但是,它表示:运算符“==”不能应用于“int”和“System.Collections.Generic.IEnumerable”类型的操作数。我想我知道这其中的原因,因为我试图将单个int与整个集合进行比较。但是如何与列表中的每一项intStep和intLogID进行比较呢?我似乎不能对这件事耿耿于怀。我是否在某处使用foreach循环?有人能让我回到正轨吗

抱歉,如果标题有点模糊,我想不出一个好标题。

如果FunctionNumber和SubFunctionNumber都是int:s。然后您可以将条件更改为:

lstPareto.Select(b => b.intStep).Contains(a.FunctionNumber) 
&&  lstPareto.Select(c => c.intStep).Contains(a.SubFunctionNumber)
更新

原因很可能是查询中没有.ToList、.First、.Single。这取决于你的期望。您可以将其更改为:

var subFuncName = (from a in m_dcSQL_ConnectionProdTest.DC3_SubFunctions
                  where a.VersionIndex == versionIndex && lstPareto.Select(b => b.intStep).Contains(a.FunctionNumber) 
                  &&  lstPareto.Select(c => c.intStep).Contains(a.SubFunctionNumber)
                  select a.SubFunctionName).ToList();
参考:


谢谢你的快速回答,它确实解决了最初的问题。然而,出现了一个新问题。如果我进行调试并在每个查询处设置断点,那么前3个查询将获得正确的值。第四个没有得到任何信息,说这是一个数据查询。如果我展开results视图以查看查询输出的内容,它会显示以下内容:由于先前的函数计算超时,因此禁用了函数计算。您必须继续执行才能重新启用函数求值。@St0ffer:更新了应答。看起来这不是什么问题,因为我可以将函数名添加到列表中。唯一的问题是在调试时看到变量包含什么,以及为什么会发生这种情况我不知道。哦,对不起,在发布之前没有看到您的评论。我只是试着添加ToList,但它仍然说明了评估的问题。