private void ExecuteDetainStudentCommand(object sender) { StudentBusinessLogic StBusiness = new StudentBusinessLogic(); IEnumerable <STUD_Students_Master> students = (from st in StBusiness.GetAllStudents() join ds in this._detainStudentList on st.Student_ID equals ds.StudentId select st); IEnumerable <STUD_StudentAcademic_Details> accDetails = StBusiness.GetAllStudentsAccademicDetails().Where(S => S.IsActive == true); List <STUD_StudentAcademic_Details> detainstudentsacc = new List <STUD_StudentAcademic_Details>(); IEnumerable <STUD_DetainingOrPromotions_Details> detorpromo = StBusiness.GetAllStudentsDetainOrPromotion(); List <STUD_DetainingOrPromotions_Details> detainorpromotion = new List <STUD_DetainingOrPromotions_Details>(); foreach (STUD_Students_Master detainst in students) { detainstudentsacc.AddRange((from stacc in accDetails where stacc.Student_ID == detainst.Student_ID && stacc.AcademicDet_ID == detainst.CurrentAcaDetail_ID select stacc)); detainorpromotion.AddRange((from dop in detorpromo where dop.Student_ID == detainst.Student_ID && dop.CurrentAcadDetail_ID == detainst.CurrentAcaDetail_ID select dop)); } foreach (DetainStudentModel ds in this._detainStudentList) { detainstudentsacc.Where(S => S.Student_ID == ds.StudentId).Select(A => { A.Section_ID = ds.SectionId; A.Standard_ID = ds.StandardID; return(A); }).ToList(); students.Where(S => S.Student_ID == ds.StudentId).Select(A => { A.CurrentStd_ID = ds.StandardID; return(A); }).ToList(); detainorpromotion.Where(A => A.Student_ID == ds.StudentId).Select(S => { S.Status_ID = 2; //Status for detain S.EnteredBy = S360Model.S360Configuration.Instance.UserID; S.Login_ID = S360Model.S360Configuration.Instance.LoginID; return(S); }).ToList(); } StBusiness.DetainStudents(students, detainstudentsacc, detainorpromotion); }