c# GroupBy分组 去重

/// <summary>
/// 根据 RoleID And SectionStr 获取 UserInfoList
/// </summary>
/// <returns></returns>
public ActionResult GetUserDataByRoleAndSection(UserInfoViewModel viewModel)
{

IList<UserInfo> userinfolist = _service.GetUserByRoleAndSection(viewModel);

var userListvalue = userinfolist.GroupBy(p => new { p.ID, p.TrueName }).Select(g => g.First()).ToList();

if (userinfolist != null)
{
return Json(new { flag = "success", userinfolist = userListvalue });
}

return Json(new { flag = "error" });

}

转载于:https://www.cnblogs.com/yibu/p/4788868.html

上一篇:Pandas数据聚合与分组


下一篇:用group时count和sum