我有一个键/值表在我的数据库,我将返回字典的列表。 下面的代码适用于我,但有很多数据没有执行。从列表中提高转化为List <词典<字符串,字符串>>使用LINQ
注:r.name不包含独特的价值
List<Dictionary<string, string>> listOutput = null;
using (ExampleDB db = new ExampleDB())
{
var result = (from r in db.FormField
where r.Form_id == 1
select new { r.ResponseId, r.name, r.value}).toList();
listOutput = new List<Dictionary<string, string>>();
foreach (var element in result)
{
listOutput.Add((from x in listOutput
where x.ResponseId == element.ResponseId
select x).ToDictionary(x => x.name, x => x.value));
}
}
return listOutput;
你有关于如何提高这个代码的建议吗?
您添加到基于现有的名单,这似乎很奇怪,我的列表中。我不明白你想要做什么 - 你能给出一个输入数据样本和预期结果吗? – 2014-12-03 18:22:02
我不确定我能理解你为什么选择字典清单。为什么不创建一个自定义类来保存变量? – paqogomez 2014-12-03 18:22:11