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 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 btnCompQuery_Click(object sender, EventArgs e) { //Compiled Query, szybsze var compliedQuery = CompiledQuery.Compile( (SampleDataContext dataContext, int EmpID) => (from s in dataContext.EmployeesLINQ where s.ID == EmpID select s).Single()); using (SampleDataContext dbContext = new SampleDataContext()) { EmployeesLINQ emp = compliedQuery(dbContext, 1); Response.Write("<script>alert('Employee with ID 1 is " + emp.FirstName + "')</script>"); } }
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>"); } } }
private void UpdateEmployeesLINQ(EmployeesLINQ obj) { this.UpdateEmployeeLINQ(((System.Nullable <int>)(obj.ID)), obj.FirstName, obj.LastName, obj.Gender, ((System.Nullable <int>)(obj.Salary)), ((System.Nullable <int>)(obj.DepartmentId))); }
private void detach_EmployeesLINQ(EmployeesLINQ entity) { this.SendPropertyChanging(); entity.DepartmentsLINQ = null; }
private void DeleteEmployeesLINQ(EmployeesLINQ obj) { this.DeleteEmployeeLINQ(((System.Nullable <int>)(obj.ID))); }