我有一个Report模型:
public class Report
{
[Key]
public int Id { get; set; }
public string ReporterId { get; set; }
[ForeignKey("ReporterId")]
public virtual ApplicationUser Reporter { get; set; }
public int ProductId { get; set; }
[ForeignKey("ProductId")]
public virtual Product Product { get; set; }
public ReportType ReportType { get; set; }
}现在,我希望将基于List<Report>的最重复元素排序的ProductId返回到重复次数最少的元素。
有没有办法用linq来做这件事?
发布于 2022-05-01 16:09:14
试试这个:
var newList = List.GroupBy(p=> p.ProductId )
.OrderByDescending(x=> x.Count())
.SelectMany(x=> x).ToList();https://stackoverflow.com/questions/72078133
复制相似问题