Пример #1
0
 public void AttachAll03()
 {
     var db1 = CreateDB();
     var employee1 = db1.Employees.First();
     var employees = new Employee[] { new Employee { EmployeeID = employee1.EmployeeID } };
     db1.Employees.AttachAll(employees);
 }
Пример #2
0
        public void Attach01()
        {
            var db1 = CreateDB();
            var employee = new Employee();

            db1.Employees.Attach(employee);
        }
Пример #3
0
        public void Attach02()
        {
            var db1 = CreateDB();
            var db2 = CreateDB();
            var employee = new Employee();

            db1.Employees.Attach(employee);
            employee.Address = "new address";

            db2.Employees.Attach(employee);
        }
        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();
        }
Пример #5
0
 public void AttachAll02()
 {
     var db1 = CreateDB();
     var employees = new Employee[] { new Employee { EmployeeID = 20 }, new Employee { EmployeeID = 20 } };
     db1.Employees.AttachAll(employees);
 }
Пример #6
0
 partial void DeleteEmployee(Employee instance);
Пример #7
0
 partial void InsertEmployee(Employee instance);
Пример #8
0
 partial void UpdateEmployee(Employee instance);
Пример #9
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
        }
Пример #10
0
 private void detach_Employees(Employee entity)
 {
     this.SendPropertyChanging();
     entity.ReportsToEmployee = null;
 }
Пример #11
0
		public void Employees_Detach(Employee entity)
		{
			entity.ReportsToEmployee = null;
		}
Пример #12
0
		public void Employees_Attach(Employee entity)
		{
			entity.ReportsToEmployee = this;
		}
Пример #13
0
		private void Employees_Attach(Employee entity)
		{
			this.SendPropertyChanging();
			entity.ReportsToEmployee = this;
		}
        public void DateTimeDiffTotalDaysSelectWithNulls02()
        {
            Northwind db = CreateDB();

            var employee = new Employee
            {
                FirstName = "Test First",
                LastName = "Test Last",
            };
            db.Employees.InsertOnSubmit(employee);
            db.SubmitChanges();

            DateTime firstDate = db.Employees.First().BirthDate.Value;

            DateTime parameterDate = firstDate.Date.AddDays(2);
            parameterDate = parameterDate.Date.AddHours(12);

            try
            {
                var query = from e in db.Employees
                            where e.BirthDate.HasValue
                            select (e.BirthDate.Value - parameterDate).TotalDays;

                var list = query.ToList();

                Assert.Greater(list.Count, 0);
            }
            finally
            {
                db.Employees.DeleteOnSubmit(employee);
                db.SubmitChanges();
            }
        }
        public void DateTimeDiffTotalDaysSelectWithNulls01()
        {
            
            Northwind db = CreateDB();

            var employee = new Employee
            {
                FirstName = "Test First",
                LastName  = "Test Last",
            };
            db.Employees.InsertOnSubmit(employee);
            db.SubmitChanges();

            DateTime firstDate = db.Employees.First().BirthDate.Value;
            firstDate.Date.AddDays(2);
            DateTime parameterDate = firstDate.Date.AddHours(12);

            try
            {
                //this test should throw an invalid operation exception since one BirthDate is null so select clausle should crash
                var query = from e in db.Employees
                            select (e.BirthDate.Value - parameterDate).TotalDays;

                var list = query.ToList();

                Assert.Greater(list.Count, 0);
            }
            finally
            {
                db.Employees.DeleteOnSubmit(employee);
                db.SubmitChanges();
            }
        }