I am facing an issue and cannot find any suitable solution for it. I have a nested dictionary that has a layout like this:
var dict = new Dictionary<int, Dictionary<string , dynamic>>()
{
0 : {Name : "abc" , marks1 : 05 , Marks2 : 10 , marks3 : 39},
1 : {Name : "efg" , marks1 : 20 , Marks2 : 30 , marks3 : 25},
2 : {Name : "hig" , marks1 : 30 , Marks2 : 40 , marks3 : 33},
3 : {Name : "xyz" , marks1 : 40 , Marks2 : 10 , marks3 : 50}
}
I am trying to query using LINQ to get the id of those queries, which are true but I am unable to select two or three criteria for a query. For one key-value the below query works fine:
var query = from id in dict
from info in id.Value
where (info.Key == "marks1" && Convert.ToDouble(info.Value) > 10)
select id
But when I try 2 or 3 criteria to get the id of row for e.g below it does not work.
var query = from id in dict
from info in id.Value
where (info.Key == "marks1" && Convert.ToDouble(info.Value) > 10)
&& (info.Key == "marks2" && Convert.ToDouble(info.Value) > 20)
select id
Also if I have to compare the values with each other like values of marks1 should be greater the mark2 and mark3. How can I execute such query? Especially when I am not allowed to access value by key like this:
info["marks1"] > ( info["mark2"] && info["marks3"] )
in LINQ as it gives me the following error:
cannot apply indexing with [] to an expression of type 'keyvaluepair < string , dynamic>
info.Key == "marks1" && info.Key == "marks2", but you probably wantinfo.Key == "marks1" || info.Key == "marks2"(mind the Logical OR)