I am in the process of converting my application chart from predefined data to a database.
I used to use this:
var data = new Dictionary<string, double>();
switch (graphselected)
{
case "1":
data = new Dictionary<string, double>
{
{"Dave", 10.023f},
{"James", 20.020f},
{"Neil", 19.203f},
{"Andrew", 4.039f},
{"Steve", 5.343f}
};
break;
case "2":
data = new Dictionary<string, double>
{
{"Dog", 10.023f},
{"Cat", 20.020f},
{"Owl", 19.203f},
{"Rat", 16.039f},
{"Bat", 27.343f}
};
break;
}
foreach (var item in list)
{
seriesDetail.Points.AddXY(item.Key, item.Value);
}
And here is what I am trying to do:
var list = new List<KeyValuePair<string, double>>();
switch (graphselected)
{
case "1":
var query = (from x in db2.cd_CleardownCore
where x.TimeTaken >= 10.0
select new { x.IMEI, x.TimeTaken }).ToList();
list = query;
break;
}
My error code is:
list = query;
With an error:
Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>'
to 'System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<string,double>>'
How can I implement the conversion?
source
share