我的结构如下:
Dictionary<string,Dictionary<int,MyObject>> GetItForMe;这将是非常简单的通过一个外汇,但我想要通过一个查询通过linq。
因此,当MyObject满足我的过滤器时,我想通过linq检索。例如:
MyObject.Number == 1 && MyObject.ThisString == "MyString"我希望匹配的记录返回上述数据结构--因此查询返回上述字典字典。我不希望它只返回匹配的MyOjbect。
发布于 2017-09-09 06:08:32
你可以试试这样的方法:
var result = GetItForMe.Where(x=>x.Value
.Where(y => y.Value.Number == 1
&& y.Value.ThisString == "MyString"))
.ToDictionary(x => x.Key, x => x.Value);本质上,我们应用了一个Where过滤,以便整理出我们不希望包含在第二个字典中的对象。
发布于 2017-09-09 06:19:50
这是小提琴
可能你在找这样的东西
GetItForMe.Where(k => k.Value.Any(ik => ik.Value.MyNum == 1 && ik.Value.MyString == "bar")).ToDictionary(d => d.Key, d => d.Value);https://stackoverflow.com/questions/46127652
复制相似问题