List多列group分组简单示例

  • binGe博客
  • C#
  • 2024/3/7 14:00:52
  • 人已阅读
简介
    /// <summary>
        /// 测试接口
        /// </summary>
        /// <returns></returns>
        [HttpPost, AllowAnonymous]
        public async Task<JsonReturn<dynamic>> TestInterface2()
        {
            //List多列group分组简单示例
            var list = new List<dynamic>();
            list.Add(new { UserID = 1, FileDirectoryID = 2, CommunityID = 3, ReadAuthType = 10 });
            list.Add(new { UserID = 1, FileDirectoryID = 2, CommunityID = 4, ReadAuthType = 20 });

            var groupList = list.GroupBy(e => new { e.UserID, e.FileDirectoryID });
            var result = groupList.Select(e => new
            {
                UserID = e.FirstOrDefault().UserID,
                FileDirectoryID = e.FirstOrDefault().FileDirectoryID,
                //CommunityID = e.Where(x => x.ReadAuthType == e.Max(e => e.ReadAuthType)).FirstOrDefault().CommunityID,
                ReadAuthType = e.Max(e => e.ReadAuthType),
            });
            return new() { Data = result };
        }

 

文章评论

评论
  • 消灭零回复
Top