C# linq 使用Groupby lamda 獲取非重復數據


 

var bookkeeperlist = await db.Bookkeeper.Where(a => a.AgentUserId == userId && a.ServiceItem == 1).GroupBy(b => b.BasicUserId).Select(a => new MyServicesListViewModel()
                    {
                        HeadIcon = apiUrl + a.FirstOrDefault(m => m.BasicUserId == a.Key).Basic_User.HeadIcon,
                        UserName = a.FirstOrDefault(m => m.BasicUserId == a.Key).Basic_User.RealName,
                        Mobile = a.FirstOrDefault(m => m.BasicUserId == a.Key).Basic_User.Mobile,
                        DepartmentName = a.FirstOrDefault(m => m.BasicUserId == a.Key).Basic_User.Sys_Department.FullName,
                        CompanyName = a.FirstOrDefault(m => m.BasicUserId == a.Key).Agent_Company.CompanyName,
                        FlowName = a.FirstOrDefault(m => m.BasicUserId == a.Key).Agent_Bill.Agent_Flow.FlowName,
                        ServiceItem = a.FirstOrDefault(m => m.BasicUserId == a.Key).ServiceItem
                    }).ToListAsync();
                    return bookkeeperlist;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM