The following query LINQ takes all the parameters and all the stations and uses them to create a string and also stores them in a list of key pairs / value idestacion / parameter. To avoid confusion I have to clarify that this row:
from x in selection.parameters
represents x stations, and each has x parameters
the first select takes well the X stations (selection.parameters) and their X parameters (x.parameters) in 'Result'
but in the second select nested in 'Values' only takes the parameters of the first station:
var selectionData = from x in selection.Parameters
select new
{
Result = "(p.col_IdEstacion = " + x.Station + "
and p.col_Sigla in(" + ("'" + string.Join("','", x.Parameters) + "'") + "))",
Values = (from y in x.Parameters
select new KeyValuePair<string, string>
(x.Station.ToString(), y)).ToList()
};
the reason why I think Values is to also take all the pairs of stations, parameter and put them in a list with addRange, I wanted to take all the pairs with LINQ
List<KeyValuePair<string, string>> myList
UPDATED : the LINQ is taking the values, but I am inserting them incorrectly in the list:
valores.AddRange(selectionData.Select(d => d.Values).FirstOrDefault());
must be the FirstOrDefault () function that only takes one station, how could you add them all?
ANSWER : values.AddRange (selectionData. SelectMany (d = > d.Values)), Thanks Alberto was just what I needed