public void AdditionOfNewEmployeeAssosiatedWithTerritoties() { using (var connection = new Northwind()) { Employee newEmployee = new Employee { FirstName = "Yana", LastName = "Haiduk" }; try { connection.BeginTransaction(); newEmployee.EmployeeId = Convert.ToInt32(connection.InsertWithIdentity(newEmployee)); connection.Territories.Where(t => t.TerritoryDescription.Length <= 5) .Insert(connection.EmployeeTerritories, t => new EmployeeTerritory { EmployeeId = newEmployee.EmployeeId, TerritoryId = t.TerritoryId }); connection.CommitTransaction(); } catch { connection.RollbackTransaction(); } } }
public void Task3_1() { Employee employee = new Employee { FirstName = "Kate", LastName = "Dailid" }; try { dbNorthwind.BeginTransaction(); employee.EmployeeId = Convert.ToInt32(dbNorthwind.InsertWithIdentity(employee)); dbNorthwind.Territories.Where(t => t.Region.RegionDescription == "Eastern") .Insert(dbNorthwind.EmployeeTerritories, t => new EmployeeTerritory { EmployeeId = employee.EmployeeId, TerritoryId = t.TerritoryId }); dbNorthwind.CommitTransaction(); } catch { dbNorthwind.RollbackTransaction(); } }
public void SetUp() { con = new Northwind(); tran = con.BeginTransaction(); }