コード例 #1
0
        public void TestMultiDeleteEntity()
        {
            int empKey = -1;
            int ordKey = -1;
            CustomerGroup custGroup = new CustomerGroup();
            custGroup.es.Connection.Name = "ForeignKeyTest";
            EmployeeCollection empColl = new EmployeeCollection();
            empColl.es.Connection.Name = "ForeignKeyTest";
            Employee emp = new Employee();
            emp.es.Connection.Name = "ForeignKeyTest";
            Employee testEmp = new Employee();
            testEmp.es.Connection.Name = "ForeignKeyTest";
            Customer cust = new Customer();
            cust.es.Connection.Name = "ForeignKeyTest";
            Order ord = new Order();
            ord.es.Connection.Name = "ForeignKeyTest";

            try
            {
                using (esTransactionScope scope = new esTransactionScope())
                {
                    // Setup
                    custGroup.GroupID = "YYYYY";
                    custGroup.GroupName = "Test";
                    custGroup.Save();

                    emp = empColl.AddNew();
                    emp.LastName = "LastName";
                    emp.FirstName = "FirstName";

                    cust = emp.CustomerCollectionByStaffAssigned.AddNew();
                    cust.CustomerID = "YYYYY";
                    cust.CustomerSub = "YYY";
                    cust.CustomerName = "Test";
                    cust.str().DateAdded = "2007-01-01 00:00:00";
                    cust.Active = true;
                    cust.Manager = 1;

                    ord = emp.OrderCollectionByEmployeeID.AddNew();
                    ord.CustID = "YYYYY";
                    ord.CustSub = "YYY";
                    ord.str().OrderDate = "2007-01-01";

                    empColl.Save();
                    empKey = emp.EmployeeID.Value;
                    ordKey = ord.OrderID.Value;

                    Assert.AreEqual(1, emp.CustomerCollectionByStaffAssigned.Count);
                    Assert.AreEqual(1, emp.OrderCollectionByEmployeeID.Count);
                    Assert.AreEqual(emp.EmployeeID.Value, cust.StaffAssigned.Value);
                    Assert.AreEqual(emp.EmployeeID.Value, ord.EmployeeID.Value);

                    // Test
                    testEmp.LoadByPrimaryKey(empKey);
                    testEmp.OrderCollectionByEmployeeID.MarkAllAsDeleted();
                    testEmp.CustomerCollectionByStaffAssigned.MarkAllAsDeleted();
                    testEmp.MarkAsDeleted();
                    testEmp.Save();

                    emp = new Employee();
                    emp.es.Connection.Name = "ForeignKeyTest";
                    Assert.IsFalse(emp.LoadByPrimaryKey(empKey));

                    ord = new Order();
                    ord.es.Connection.Name = "ForeignKeyTest";
                    Assert.IsFalse(ord.LoadByPrimaryKey(ordKey));

                    cust = new Customer();
                    cust.es.Connection.Name = "ForeignKeyTest";
                    Assert.IsFalse(cust.LoadByPrimaryKey("YYYYY", "YYY"));
                }
            }
            finally
            {
                // Clean up
                ord = new Order();
                ord.es.Connection.Name = "ForeignKeyTest";
                if (ord.LoadByPrimaryKey(ordKey))
                {
                    ord.MarkAsDeleted();
                    ord.Save();
                }

                cust = new Customer();
                cust.es.Connection.Name = "ForeignKeyTest";
                if (cust.LoadByPrimaryKey("YYYYY", "YYY"))
                {
                    cust.MarkAsDeleted();
                    cust.Save();
                }

                emp = new Employee();
                emp.es.Connection.Name = "ForeignKeyTest";
                if (emp.LoadByPrimaryKey(empKey))
                {
                    emp.MarkAsDeleted();
                    emp.Save();
                }

                custGroup = new CustomerGroup();
                custGroup.es.Connection.Name = "ForeignKeyTest";

                if (custGroup.LoadByPrimaryKey("YYYYY"))
                {
                    custGroup.MarkAsDeleted();
                    custGroup.Save();
                }
            }
        }
コード例 #2
0
		public void TestSave()
		{
            int empKey = -1;
            CustomerGroup custGroup = new CustomerGroup();
            custGroup.es.Connection.Name = "ForeignKeyTest";
            Employee emp = new Employee();
            emp.es.Connection.Name = "ForeignKeyTest";
            Customer cust = new Customer();
            cust.es.Connection.Name = "ForeignKeyTest";

            try
            {
                using (esTransactionScope scope = new esTransactionScope())
                {
                    custGroup.GroupID = "XXXXX";
                    custGroup.GroupName = "Test";
                    custGroup.Save();

                    emp.LastName = "LastName";
                    emp.FirstName = "FirstName";

                    cust = emp.CustomerCollectionByStaffAssigned.AddNew();
                    cust.CustomerID = "XXXXX";
                    cust.CustomerSub = "XXX";
                    cust.CustomerName = "Test";
                    cust.str().DateAdded = "2007-01-01 00:00:00";
                    cust.Active = true;
                    cust.Manager = 1;

                    emp.Save();
                    empKey = emp.EmployeeID.Value;

                    Assert.AreEqual(1, emp.CustomerCollectionByStaffAssigned.Count);
                    Assert.AreEqual(emp.EmployeeID.Value, cust.StaffAssigned.Value);
                }
            }
            finally
            {
                // Clean up
                emp = new Employee();
                emp.es.Connection.Name = "ForeignKeyTest";

                if (emp.LoadByPrimaryKey(empKey))
                {
                    CustomerCollection custColl = emp.CustomerCollectionByStaffAssigned;
                    custColl.MarkAllAsDeleted();
                    emp.MarkAsDeleted();
                    emp.Save();

                }

                custGroup = new CustomerGroup();
                custGroup.es.Connection.Name = "ForeignKeyTest";

                if (custGroup.LoadByPrimaryKey("XXXXX"))
                {
                    custGroup.MarkAsDeleted();
                    custGroup.Save();
                }
            }
		}
コード例 #3
0
		public void TestSaveComposite()
		{
            int ordKey = -1;
            CustomerGroup custGroup = new CustomerGroup();
            custGroup.es.Connection.Name = "ForeignKeyTest";
            Customer cust = new Customer();
            cust.es.Connection.Name = "ForeignKeyTest";
            Order ord = new Order();
            ord.es.Connection.Name = "ForeignKeyTest";

            try
            {
                using (esTransactionScope scope = new esTransactionScope())
                {
                    custGroup.GroupID = "XXXXX";
                    custGroup.GroupName = "Test";
                    custGroup.Save();

                    cust.CustomerID = "XXXXX";
                    cust.CustomerSub = "XXX";
                    cust.CustomerName = "Test";
                    cust.str().DateAdded = "2007-01-01 00:00:00";
                    cust.Active = true;
                    cust.Manager = 1;

                    ord = cust.OrderCollectionByCustID.AddNew();
                    ord.str().OrderDate = "2007-12-31 00:00:00";

                    cust.Save();
                    ordKey = ord.OrderID.Value;

                    Assert.AreEqual(1, cust.OrderCollectionByCustID.Count);
                }
            }
            finally
            {
                // Clean up
                cust = new Customer();
                cust.es.Connection.Name = "ForeignKeyTest";

                if (cust.LoadByPrimaryKey("XXXXX", "XXX"))
                {
                    OrderCollection ordColl = cust.OrderCollectionByCustID;
                    ordColl.MarkAllAsDeleted();
                    cust.MarkAsDeleted();
                    cust.Save();
                }

                custGroup = new CustomerGroup();
                custGroup.es.Connection.Name = "ForeignKeyTest";

                if (custGroup.LoadByPrimaryKey("XXXXX"))
                {
                    custGroup.MarkAsDeleted();
                    custGroup.Save();
                }
            }
		}