var distinctAllEvaluationLicenses = allEvaluationLicenses.GroupBy((License =>
License.dateCreated)).Select(License => License.First());
如何选择最新的“dateCreated”而不是第一个?
var distinctAllEvaluationLicenses = allEvaluationLicenses.GroupBy((License =>
License.dateCreated)).Select(License => License.First());
如何选择最新的“dateCreated”而不是第一个?
如果你想要的只是 max dateCreated
,试试这个:
var results = allEvaluationLicenses.Max(x => x.dateCreated);
如果您想要具有 max 的许可证dateCreated
,请尝试以下操作:
var results =
allEvaluationLicenses.GroupBy(x => x.dateCreated)
.OrderByDescending(g => g.Key)
.First();
或者在查询语法中:
var results =
(from l in allEvaluationLicenses
group l by l.dateCreated into g
orderby g.Key descending
select g)
.First();
您可以使用Max
来获得最大的序列。
var distinctAllEvaluationLicenses = allEvaluationLicenses.GroupBy(License =>
License.dateCreated)
.Max(group => group.Key);
也就是说,在这种特殊情况下,似乎根本没有任何理由进行分组:
var distinctAllEvaluationLicenses = allEvaluationLicenses
.Max(License=> License.dateCreated)