示例#1
0
 protected void BtmUpdate(object sender, EventArgs e)
 {
     using (SampleDataContext dbContext = new SampleDataContext())
     {
         Employees employee = dbContext.Employees.SingleOrDefault(x => x.ID == 8);
         employee.Salary = 65000;
         dbContext.SubmitChanges();
     }
     GetData();
 }
示例#2
0
 protected void GetEmpoyeesByDepartment(object sender, EventArgs e)
 {
     using (SampleDataContext dbContext = new SampleDataContext())
     {
         string deptName = string.Empty;
         GridView1.DataSource = dbContext.GetEmployeesByDepartment(1, ref deptName);
         GridView1.DataBind();
         lblDept.Text = "Le nom du département est :" + deptName;
     }
     GetData();
 }
示例#3
0
 protected void BtmDelete(object sender, EventArgs e)
 {
     using (SampleDataContext dbContext = new SampleDataContext())
     {
         try
         {
             Employees employee = dbContext.Employees.SingleOrDefault(x => x.ID == 10);
             dbContext.Employees.DeleteOnSubmit(employee);
             dbContext.SubmitChanges();
         }
         catch (Exception ex)
         {
             ExceptionMethod(ex);
         }
     }
     GetData();
 }
示例#4
0
        private void GetData()
        {
            SampleDataContext dbContext = new SampleDataContext();

            //dbContext.Log = Response.Output;
            // première solution pour récupérer tous les employés de la table
            var linqQuery = from employee in dbContext.Employees
                            select employee;

            //troisième façon de le faire avec une lambda expression
            var lindQuery3 = dbContext.Employees.Select(x => x);
            //Response.Write(dbContext.GetCommand(linqQuery).CommandText);

            // deuxième solution pour récupérer tous les employés de la table avec une procédure stokée
            var linqQuery2 = dbContext.GetEmployees();

            GridView1.DataSource = lindQuery3;
            GridView1.DataBind();
        }
示例#5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SampleDataContext dbContext = new SampleDataContext();
            var linqQuery = from employee in dbContext.Employees
                            join departement in dbContext.Departments
                            on employee.DepartmentId equals departement.ID
                            where departement.Location == "London"
                            select new { employee.FirstName, employee.LastName, departement.Location };

            var linqQuery4 = from employee in dbContext.Employees
                             join departement in dbContext.Departments
                             on employee.DepartmentId equals departement.ID
                             where departement.Location == "London"
                             select new { employee.FirstName, employee.LastName, departement.Location };

            var linqQuery2 = dbContext.Employees.
                             Join(dbContext.Departments,
                                  empl => empl.DepartmentId,
                                  depart => depart.ID,
                                  (empl, depart) => new { Empl = empl, Depart = depart }).
                             Where(x => x.Depart.Location == "London").
                             Where(x => x.Empl.Gender == "Male").
                             Select(x => new { x.Empl.FirstName, x.Empl.LastName, x.Depart.Location, x.Empl.Gender });

            var linqQuery3 = dbContext.Employees.
                             Join(dbContext.Departments,
                                  empl => empl.DepartmentId,
                                  depart => depart.ID,
                                  (empl, depart) => new { Empl = empl, Depart = depart }).
                             Where(x => x.Depart.Location == "London").
                             Select(x => new { x.Empl.FirstName, x.Empl.LastName, x.Depart.Location });

            var linqQuery5 = dbContext.Employees.GroupBy(x => x.Salary).OrderBy(x => x.Min()).
                             Select(x => x.Key).ToList();

            GridView1.DataSource = linqQuery5;
            GridView1.DataBind();
        }
示例#6
0
 protected void BtmInsert(object sender, EventArgs e)
 {
     try
     {
         using (SampleDataContext dbContext = new SampleDataContext())
         {
             Employees newEmployee = new Employees
             {
                 FirstName    = "jean",
                 LastName     = "Fred",
                 Gender       = "Male",
                 Salary       = 50000,
                 DepartmentId = 1,
             };
             dbContext.Employees.InsertOnSubmit(newEmployee);
             dbContext.SubmitChanges();
         }
         GetData();
     }
     catch (Exception ex)
     {
         ExceptionMethod(ex);
     }
 }