Wednesday, November 15, 2017

split with linq

===============Final Result============
List data= entity.Bind_Employee.Select(e => new tbl_Employee
                                {
                                    Empno = e.Empno,
                                    EName = e.EName,

                                    Educations = entity.Bind_Education.Where(k => e.Edu_ids.Split(',').Select(x => int.Parse(x)).ToList().Contains(k.EDU_ID))
                                    .Select(k => new tbl_Education {EDU_Name = k.EDU_Name,EDU_ID=k.EDU_ID }).ToList()
                                }).ToList();


======================================













 var result= entity.Bind_Employee.Where(k=>k.Empno==1001).Select(k=>k.Edu_ids).FirstOrDefault();

            List ids = result.Split(',').Select(x => int.Parse(x)).ToList();

            var temp = entity.Bind_Education.Where(k=>ids.Contains(k.EDU_ID)).Select(k=>k.EDU_Name);

            List model = (from e in entity.Bind_Employee
                      join ed in entity.Bind_Emp_EDU on e.Empno equals ed.Empno
                      join edu in entity.Bind_Education on ed.EDU_ID equals edu.EDU_ID
                      select
                        (
                        new tbl_Employee
                        {
                            Empno=e.Empno,
                            EName=e.EName,
                            Edu_ids=e.Edu_ids,
                            Educations =entity.Bind_Education.Where(k=>e.Edu_ids.Split(',').Select(x => int.Parse(x)).ToList().Contains(k.EDU_ID)).Select(k=>k).ToList()
                        })).ToList();


            return View(model);
        }




   List data = entity.Emps.Select(e => new EmployeeModel1 {
                                Empno=e.Empno,
                                Ename=e.Ename,
                                Job=e.Job,
                                Comm=e.Comm,
                                Deptno=e.Deptno,
                                Mgr=e.Mgr,
                                HireDate=e.HireDate,
                                Sal=e.Sal,
                                Department=(from d in entity.Depts where d.Deptno==e.Deptno select new DepartmentModel1 {DName=d.DName }).FirstOrDefault(),
                                Designations=(from ed in entity.tbl_Emp_Details where ed.Empno==e.Empno                           
                                from ds in entity.tbl_Designation where ds.Desig_ID==ed.Desig_ID
                                select new DesignationModel
                                {
                                    Desig_ID=ds.Desig_ID,
                                    Desig_Name=ds.Desig_Name
                                }).ToList(),
                                Educations=entity.tbl_Education.Where(k=>e.EDU_ID.Split(',').Select(x => int.Parse(x)).ToList().Contains(k.EDU_ID))
                                .Select(k => new EducationModel {EDU_ID=k.EDU_ID,EDU_Name=k.EDU_Name }).ToList()
            }).ToList();

No comments:

Post a Comment

javascript Filter/index off

 var family = [{"name":"Jack",  "age": 26},               {"name":"Jill",  "age"...