Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var result = Employee.GetAllEmployees().Join(
                Departmen.GetAllDepartments(),
                x => x.DepartmentID,
                d => d.ID,
                (employee, department) => new
            {
                DepartmentName = department.Name,
                EmployeeName   = employee.Name
            });

            foreach (var r in result)
            {
                Response.Write(r.EmployeeName + "-" + r.DepartmentName + "<br/>");
            }
            Response.Write("<hr /> SQl like <br/>");
            var resultSql = from x in Employee.GetAllEmployees()
                            join d in Departmen.GetAllDepartments()
                            on x.DepartmentID equals d.ID
                            select new
            {
                EmployeeName   = x.Name,
                DepartmentName = d.Name
            };

            foreach (var r in resultSql)
            {
                Response.Write(r.EmployeeName + "-" + r.DepartmentName + "<br/>");
            }
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var result = from x in Employee.GetAllEmployees()
                         from d in Departmen.GetAllDepartments()
                         select new { x, d };

            foreach (var r in result)
            {
                Response.Write(r.x.Name + "-" + r.d.Name + "<br/>");
            }
            Response.Write("<hr/>");
            var results = Employee.GetAllEmployees().SelectMany(x => Departmen.GetAllDepartments(),
                                                                (x, d) => new { x, d });

            foreach (var r in results)
            {
                Response.Write(r.x.Name + "-" + r.d.Name + "<br/>");
            }
            Response.Write("<hr/>");
            var res = Employee.GetAllEmployees().Join(Departmen.GetAllDepartments(), x => true, d => true, (x, d) => new { x, d });

            foreach (var r in res)
            {
                Response.Write(r.x.Name + "-" + r.d.Name + "<br/>");
            }
        }
Ejemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var EmployeeByDepartment = Departmen.GetAllDepartments()
                                       .GroupJoin(Employee.GetAllEmployees(),
                                                  d => d.ID,
                                                  x => x.DepartmentID,
                                                  (department, employees) => new
            {
                Department = department,
                Employees  = employees
            });

            foreach (var department in EmployeeByDepartment)
            {
                Response.Write(department.Department.Name + "<Br/>");
                foreach (var emp in department.Employees)
                {
                    Response.Write("  " + emp.Name + "<br/>");
                }
                Response.Write("<br/>");
            }

            Response.Write("<hr/> Sql like<br/>");
            var EmployeeByDepartmentSQl = from d in Departmen.GetAllDepartments()
                                          join x in Employee.GetAllEmployees()
                                          on d.ID equals x.DepartmentID into eGroup
                                          select new
            {
                department = d,
                Employees  = eGroup
            };

            foreach (var department in EmployeeByDepartmentSQl)
            {
                Response.Write(department.department.Name + "<Br/>");
                foreach (var emp in department.Employees)
                {
                    Response.Write("  " + emp.Name + "<br/>");
                }
                Response.Write("<br/>");
            }
        }
Ejemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var result = from x in Employee.GetAllEmployees()
                         join d in Departmen.GetAllDepartments()
                         on x.DepartmentID equals d.ID into eGroup
                         from d in eGroup.DefaultIfEmpty()
                         select new
            {
                EmployeeName   = x.Name,
                DepartmentName = d == null?"No Departement": d.Name
            };

            foreach (var r in result)
            {
                Response.Write(r.EmployeeName + "-" + r.DepartmentName + "<br/>");
            }
            Response.Write("<hr />");
            var results = Employee.GetAllEmployees()
                          .GroupJoin(Departmen.GetAllDepartments(),
                                     x => x.DepartmentID,
                                     d => d.ID,
                                     (emp, deps) => new
            {
                emp,
                deps
            })
                          .SelectMany(z => z.deps.DefaultIfEmpty(),
                                      (a, b) => new
            {
                EmployeeName   = a.emp.Name,
                DepartmentName = b == null?"No Department":b.Name
            });

            foreach (var r in results)
            {
                Response.Write(r.EmployeeName + "-" + r.DepartmentName + "<br/>");
            }
        }