Пример #1
0
 partial void DeleteTerritory(Territory instance);
        public void LinqToSqlInsert03()
        {
            Northwind db = CreateDB();

            var ds = new DataLoadOptions();
            ds.LoadWith<Employee>(p => p.EmployeeTerritories);
            ds.LoadWith<EmployeeTerritory>(p => p.Territory);

            db.LoadOptions = ds;
            var q = from e in db.Employees where e.FirstName == "Nancy" select e;


            if (db.Employees.Any(e => e.FirstName == "Test Kira" && e.LastName == "Test Smith"))
                Assert.Ignore();


            var newEmployee = new Employee { FirstName = "Test Kira", LastName = "Test Smith" };
            var newTerritory = new Territory
            {
                TerritoryID = "12345",
                TerritoryDescription = "Test Anytown",
                Region = db.Regions.First()
            };

            var newEmployeeTerritory = new EmployeeTerritory { Employee = newEmployee, Territory = newTerritory };
            db.Employees.InsertOnSubmit(newEmployee);
            db.Territories.InsertOnSubmit(newTerritory);
            db.EmployeeTerritories.InsertOnSubmit(newEmployeeTerritory);
            db.SubmitChanges();

            // cleanup
            db.EmployeeTerritories.DeleteOnSubmit(newEmployeeTerritory);
            db.Territories.DeleteOnSubmit(newTerritory);
            db.Employees.DeleteOnSubmit(newEmployee);
            db.SubmitChanges();
        }
Пример #3
0
 partial void InsertTerritory(Territory instance);
Пример #4
0
 partial void UpdateTerritory(Territory instance);
Пример #5
0
 private void detach_Territories(Territory entity)
 {
     this.SendPropertyChanging();
     entity.Region = null;
 }
Пример #6
0
        public void LinqToSqlInsert03() {

            Northwind db2 = new Northwind(connString);

            DataLoadOptions ds = new DataLoadOptions();
            ds.LoadWith<nwind.Employee>(p => p.EmployeeTerritories);
            ds.LoadWith<nwind.EmployeeTerritory>(p => p.Territory);

            db2.LoadOptions = ds;
            var q = (
                from e in db.Employees
                where e.FirstName == "Nancy"
                select e);



            Console.WriteLine("*** BEFORE ***");
            ObjectDumper.Write(q, 1);


            Console.WriteLine();
            Console.WriteLine("*** INSERT ***");
            var newEmployee = new Employee { FirstName = "Kira",
                                             LastName = "Smith"
                                           };
            var newTerritory = new Territory { TerritoryID = "12345",
                                               TerritoryDescription = "Anytown",
                                               Region = db.Regions.First()
                                             };
            var newEmployeeTerritory = new EmployeeTerritory { Employee = newEmployee,
                                                               Territory = newTerritory
                                                             };
            db.Employees.InsertOnSubmit(newEmployee);
            db.Territories.InsertOnSubmit(newTerritory);
            db.EmployeeTerritories.InsertOnSubmit(newEmployeeTerritory);
            db.SubmitChanges();


            Console.WriteLine();
            Console.WriteLine("*** AFTER ***");
            ObjectDumper.Write(q, 2);



            Cleanup66();  // Restore previous database state
        }
Пример #7
0
		public void Territories_Detach(Territory entity)
		{
			entity.Region = null;
		}
Пример #8
0
		public void Territories_Attach(Territory entity)
		{
			entity.Region = this;
		}
Пример #9
0
		private void Territories_Attach(Territory entity)
		{
			this.SendPropertyChanging();
			entity.Region = this;
		}