using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.ViewModel.DifferentDynamic; using System.Linq.Expressions; using EMIS.Entities; namespace EMIS.DataLogic.Common.Students { public class BatchRepeatDAL : DifferentDynamicDAL { public IQueryable GetBatchRepeatProcessView(Expression> exp) { var query = (from change in DifferentDynamicRepository.GetList(exp) join user in UserRepository.Entities on change.UserID equals user.UserID join classmajor in ClassmajorRepository.Entities on change.BeforeClassmajorID equals classmajor.ClassmajorID join grade in GrademajorRepository.Entities on classmajor.GrademajorID equals grade.GrademajorID join afterGrade in GrademajorRepository.Entities on new { grade.FacultymajorID, SchoolyearID = grade.GradeID + 1 } equals new { afterGrade.FacultymajorID, SchoolyearID = afterGrade.GradeID } into dafterGrade from afterGrade in dafterGrade.DefaultIfEmpty() join afterClass in ClassmajorRepository.Entities on new { GrademajorID = (Guid?)afterGrade.GrademajorID, classmajor.ClassNum } equals new { afterClass.GrademajorID, afterClass.ClassNum } into dafterClass from afterClass in dafterClass.DefaultIfEmpty() join afterClass1 in ClassmajorRepository.Entities on afterGrade.GrademajorID equals afterClass1.GrademajorID into dafterClass1 from afterClass1 in dafterClass1.DefaultIfEmpty() group new { Change = change, AfterClass = afterClass, AfterClass1 = afterClass1 } by new { Change = change, User = user } into g select new DifferentDynamicView { EntityID = g.Key.Change.StudentChangeID, SchoolyearID = g.Key.Change.SchoolyearID, UserID = g.Key.Change.UserID, Name = g.Key.User.Name, DifferentDynamicType = g.Key.Change.ChangeTypeID, Reason = g.Key.Change.ChangeReasonID, InSchoolStatusID = g.Key.Change.BeforeInSchoolStatusID, StudentStatus = g.Key.Change.BeforeStudentStatus, //StandardID = g.Key.Change.StandardID, ClassmajorID = g.Key.Change.BeforeClassmajorID, //AfterStandardID = g.Key.Change.StandardID, AfterClassmajorID = g.Select(x => (Guid?)x.AfterClass.ClassmajorID).FirstOrDefault() ?? g.Select(x => (Guid?)x.AfterClass1.ClassmajorID).FirstOrDefault(), AfterInSchoolStatusID = g.Key.Change.AfterInSchoolStatusID, AfterStudentStatus = g.Key.Change.AfterStudentStatus, ReturnSchoolyearID = g.Key.Change.ReturnSchoolyearID, ApplyTypeID = g.Key.Change.ChangeApplyTypeID, ApplyRemark = g.Key.Change.Description, BeginTime = g.Key.Change.ChangeDate, EndTime = g.Key.Change.ChangeDate, //Source = g.Key.Change.Source, //Direction = g.Key.Change.Direction, EntityApprovalStatus = g.Key.Change.ApprovalStatus, Remark = g.Key.Change.Remark, EntityCreateTime = g.Key.Change.CreateTime, EntityApplyDate = g.Key.Change.ChangeDate, EntityCreateUserID = g.Key.Change.CreateUserID, } ); return query; } } }