【发布时间】:2009-03-06 01:54:51
【问题描述】:
这是我的 LINQ 查询,它获取每个选定列的唯一值并将它们作为列表存储在字典中。
var serialTable = serialNoAdapter.GetData();
var distinctValue = (from row in serialTable
select new
{
row.CodePractice,
row.LockType,
row.Software
}).Distinct().ToList();
var softwareValue = distinctValue.Select(p => p.Software).Distinct().ToList();
var codeValue = distinctValue.Select(p => p.CodePractice).Distinct().ToList();
var lockValue = distinctValue.Select(p => p.LockType).Distinct().ToList();
return new Dictionary<string, List<string>>()
{
{"software", softwareValue},
{"codepractice", codeValue},
{"locktype", lockValue}
};
唯一的问题是它被分解成几个语句。我的问题是是否可以简化它并将其压缩为单个语句?
【问题讨论】:
标签: linq