Пример #1
0
        private void GetData()
        {
            SampleDataContext dbContext = new SampleDataContext();

            GridView1.DataSource = dbContext.GetEmployees();
            GridView1.DataBind();
        }
Пример #2
0
 protected void btnGetEmployeesByDepartment_Click(object sender, EventArgs e)
 {
     using (SampleDataContext dbContext = new SampleDataContext())
     {
         string deptName = null;
         GridView1.DataSource = dbContext.GetEmployeesByDepartment(1, ref deptName);
         GridView1.DataBind();
         lblDept.Text = "Department " + deptName;
     }
 }
Пример #3
0
 protected void btnDelete_Click(object sender, EventArgs e)
 {
     using (SampleDataContext dbContext = new SampleDataContext())
     {
         //   Employees newEmployes = dbContext.Employees.SingleOrDefault(x => x.ID == 23);
         //   dbContext.Employees.DeleteOnSubmit(newEmployes);
         var newEmployes = from emp in dbContext.Employees
                           where emp.FirstName == "Robert"
                           select emp;
         dbContext.Employees.DeleteAllOnSubmit(newEmployes);
         dbContext.SubmitChanges();
     }
     GetData();
 }
Пример #4
0
 protected void btnUpdate_Click(object sender, EventArgs e)
 {
     using (SampleDataContext dbContext = new SampleDataContext())
     {
         //  Employees newEmployes = dbContext.Employees.SingleOrDefault(x => x.ID == 23);
         //  newEmployes.Salary = 65000;
         var newEmployes = from emp in dbContext.Employees
                           where emp.FirstName == "Robert"
                           select emp;
         foreach (Employees data in newEmployes)
         {
             data.Salary = 65000;
         }
         dbContext.SubmitChanges();
     }
     GetData();
 }
Пример #5
0
 protected void btnInsert_Click(object sender, EventArgs e)
 {
     using (SampleDataContext dbContext = new SampleDataContext())
     {
         Employees newEmployes = new Employees()
         {
             FirstName    = "Robert",
             LastName     = "K",
             Gender       = "Male",
             Salary       = 55000,
             DepartmentId = 1
         };
         dbContext.Employees.InsertOnSubmit(newEmployes);
         dbContext.SubmitChanges();
     }
     GetData();
 }
Пример #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            using (SampleDataContext dbcontext = new SampleDataContext())
            {
                dbcontext.Log = Response.Output;
                //lazy
                //gvdepartments.datasource = dbcontext.departments;
                // eager
                gvDepartments.DataSource = from dept in dbcontext.Departments
                                           select new { name = dept.Name, employees = dept.Employees };
                gvDepartments.DataBind();
            }
            //using (SampleDataContext dbContext = new SampleDataContext())
            //{
            //    dbContext.Log = Response.Output;
            //    DataLoadOptions dataLoad = new DataLoadOptions();
            //    dataLoad.LoadWith<Departments>(d => d.Employees);
            //    dbContext.LoadOptions = dataLoad;

            //    gvDepartments.DataSource = dbContext.Departments;
            //    gvDepartments.DataBind();
            //}
        }