1. 程式人生 > >linq jion多張表 group by

linq jion多張表 group by

 var total = from rua in db.rh_user_attendances
                        join rpi in db.rh_patient_infos
                        on rua.UserNumber equals rpi.UserNumber
                        join rsi in db.rh_student_infos
                        on rua.UserId equals rsi.Id
                        join rci in db.rh_course_infos
                        on rua.CourseAddress equals rci.CourseAddress
                        select new
                        {
                            Id = rua.Id,
                            teacherName = rpi.UserName,
                            teacherNumber = rpi.UserNumber,
                            TrainName = rua.TrainName,
                            CourseAddress = rua.CourseAddress,
                            studentName = rsi.UserName,
                            studentNumber = rsi.UserNumber,
                            UserRole = rsi.UserRole,
                            TrainNumber = rci.TrainNumber,
                            AttendanceTime = rua.AttendanceTime
                        };

            var totalGroup = total.Distinct();


c# 中join多張表,需要group by. 在linq語句中Distinct()函式即可實現該功能。