protected void BtCherche_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(TBZoneCherche.Text)) { switch (RBSearch.SelectedValue) { case "Project": GridViewAssigment.DataSource = (from a in dbContext.assignments where a.Project.name == TBZoneCherche.Text select new { a.EmployeeID, a.ProjectID, a.Employee.firstName, a.Employee.lastName, a.Project.name } ).ToList(); break; case "Employe": GridViewAssigment.DataSource = (from a in dbContext.assignments where a.Employee.firstName == TBZoneCherche.Text select new { a.EmployeeID, a.ProjectID, a.Employee.firstName, a.Employee.lastName, a.Project.name } ).ToList(); break; default: break; } GridViewAssigment.DataBind(); } }
private void load_grid() ////// PROBLEME { //SOLUTION 1 NE MARCHE PAS //GridViewAssigment.DataSource = (from a in dbContext.assignments // select new {a.EmployeeID, a.ProjectID , // a.Employee.firstName, a.Employee.lastName, // a.Project.name }).ToList(); //SOLUTION 1 NE MARCHE PAS AVEC SQL RAW //GridViewAssigment.DataSource = dbContext.assignments.SqlQuery("SELECT emp.employeID, p.projectID, emp.firstName, emp.lastName, p.name " + // "FROM Employees emp, Projects p, Assignments a " + // "WHERE emp.employeID = a.EmployeeID AND p.projectID = a.ProjectID").ToList(); GridViewAssigment.DataBind(); }