我有一个查询
var QP = (from a in QProductAllInfo select new { a.Id, a.Title, a.FullTitle}).Distinct();
结果是:
我需要结果:
最佳答案
假设始终将不同的ID视为不同的ID,则可以尝试此操作。
我可能会在两个查询中编写它。这样一来,调试起来很容易并且更具可读性。您可以使用MoreLinq
。
DistinctBy
Download
var temp = from a in QProductAllInfo select new { a.Id, a.Title, a.FullTitle}.ToList();
var result = temp.DistinctBy(i => i.Id);
您也可以使用
Var result = temp.GroupBy(x => x.Id).Select(y => y.First());