使用 linq 从 2 个不同的对象中进行选择
我想从 Linq 中的 2 个不同对象中进行选择以进行比较。这是我尝试过的,
var myItem = (from abc in firstList.Value
from cds in secondList
where (abc.Key.theKey == cds.secondList.theSecondKey
select cds).SingleOrDefault();
尽管我收到错误:
在调用“SelectMany”时类型推断失败
i want to select from 2 different objects in Linq in order to compare them. This is what i tried,
var myItem = (from abc in firstList.Value
from cds in secondList
where (abc.Key.theKey == cds.secondList.theSecondKey
select cds).SingleOrDefault();
although i get an error:
Type inference failed in the call to 'SelectMany'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果这是您的精确查询,可能只是因为您的括号不匹配。试试这个:
诚然,我可能会使用连接重写它 - 在大多数情况下连接会更有效。
但是,如果这不是您的确切查询,请发布一个简短但完整的程序来演示该问题。例如,尚不清楚为什么
cds
会有一个secondList
属性。演示该问题的完整示例将使事情变得简单得多。If that's your exact query, it may just be because you've got unmatched brackets. Try this:
Admittedly I would probably rewrite that using a join - in most cases the join will be more efficient.
However, if that's not your exact query, please post a short but complete program which demonstrates the problem. It's not clear why
cds
would have asecondList
property for example. A complete example demonstrating the problem would make this a lot simpler.more 中有一个左括号:
You have an opening paranthesis in more: