protected void btnUpdate_Click(object sender, EventArgs e) { using (SampleDataContext dbContext = new SampleDataContext()) { EmployeesLINQ emp = dbContext.EmployeesLINQ.SingleOrDefault(x => x.ID == 1003); emp.Salary = 65000; dbContext.SubmitChanges(); } GetData(); }
protected void btnDelete_Click(object sender, EventArgs e) { using (SampleDataContext dbContext = new SampleDataContext()) { EmployeesLINQ emp = dbContext.EmployeesLINQ.SingleOrDefault(x => x.ID == 1003); dbContext.EmployeesLINQ.DeleteOnSubmit(emp); dbContext.SubmitChanges(); } GetData(); }
protected void btnInsert_Click(object sender, EventArgs e) { using (SampleDataContext dbContext = new SampleDataContext()) { EmployeesLINQ emp = new EmployeesLINQ { FirstName = "Tim", LastName = "T", Salary = 55000, DepartmentId = 1 }; dbContext.EmployeesLINQ.InsertOnSubmit(emp); dbContext.SubmitChanges(); } GetData(); }
protected void btnCache_Click(object sender, EventArgs e) { using (SampleDataContext dbContext1 = new SampleDataContext()) { using (SampleDataContext dbContext2 = new SampleDataContext()) { EmployeesLINQ E1 = dbContext1.EmployeesLINQ.FirstOrDefault(x => x.ID == 1); EmployeesLINQ E2 = dbContext2.EmployeesLINQ.FirstOrDefault(x => x.ID == 1); Response.Write("<script>alert('E1 name " + E1.FirstName + " E2 name " + E2.FirstName + "')</script>"); E1.FirstName = "Steve"; dbContext1.SubmitChanges(); Response.Write("<script>alert('Zmiana imienia')</script>"); E2 = dbContext2.EmployeesLINQ.FirstOrDefault(x => x.ID == 1); Response.Write("<script>alert('E1 name " + E1.FirstName + " E2 name " + E2.FirstName + "')</script>"); dbContext2.Refresh(RefreshMode.OverwriteCurrentValues, E2); Response.Write("<script>alert('Reload cachu')</script>"); Response.Write("<script>alert('E1 name " + E1.FirstName + " E2 name " + E2.FirstName + "')</script>"); } } }
protected void btnAddEmp_Click(object sender, EventArgs e) { using (SampleDataContext dbContext = new SampleDataContext()) { PermanentEmployee permanentEmployee = new PermanentEmployee { Name = "Emma", Gender = "Female", AnuualSalary = 65000 }; ContractEmployee contractEmployee = new ContractEmployee { Name = "Kristie", Gender = "Female", HourlyPay = 50, HoursWorked = 80 }; dbContext.Employees2LINQ.InsertOnSubmit(permanentEmployee); dbContext.Employees2LINQ.InsertOnSubmit(contractEmployee); dbContext.SubmitChanges(); } }