Exemple #1
0
        public void PO()
        {
            //1. 创建PO对象
            Customer c = new Customer
            {
                CustomerID = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City = "Seattle",
                Country = "USA"
            };

            //2. 创建DbContext 对象
            using (var db = cfg.CreateDbContext())
            {
                //3. 创建DbSet对象
                var q = db.Set<Customer>();

                //4. 删除所有以“XX”开头的CustomerID记录
                q.Delete(p => p.CustomerID.StartsWith("XX"));

                //5. 执行PO插入
                q.Insert(c);

                //6. 从数据库中查找指定CustomerID 的PO对象
                var c2 = q.Get(c.CustomerID);
                Assert.IsNotNull(c2);
                Assert.AreNotSame(c, c2);

                Assert.AreEqual(c.CustomerID, c2.CustomerID);
                Assert.AreEqual(c.CompanyName, c2.CompanyName);
                Assert.AreEqual(c.ContactName, c2.ContactName);
                Assert.AreEqual(c.City, c2.City);
                Assert.AreEqual(c.Country, c2.Country);


                q.Delete(c);
            }
        }
        public virtual void TestCompareTwoConstantEntityNestedRelationshipNegation()
        {
            Order exclude = new Order() { OrderID = 10702 };
            Customer alfki = new Customer() { CustomerID = "ALFKI" };

            var testQuery = from o in db.Orders
                            where o.Customer == alfki &&
                                  o != exclude
                            select o;

            var test = testQuery.ToList();
            AssertValue(5, test.Count);
            AssertValue("ALFKI", test[0].CustomerID);
        }
        public virtual void TestCompareEntityConstantDirectEqualRelationship()
        {
            Customer alfki = new Customer { CustomerID = "ALFKI" };
            var testQuery = from c in db.Customers
                            where c == alfki
                            select c;

            var test = testQuery.ToList();

            AssertValue(1, test.Count);
            AssertValue("ALFKI", test[0].CustomerID);
        }
        public virtual void TestCompareEntityEntityEqualRelationship()
        {
            Customer alfki = new Customer { CustomerID = "ALFKI" };
            var testQuery = from o in db.Orders
                            from c in db.Customers
                            where o.Customer == c &&
                                  c.CustomerID == alfki.CustomerID
                            select o;

            var test = testQuery.ToList();

            AssertValue(6, test.Count);
            AssertValue("ALFKI", test[0].CustomerID);
        }
 public virtual void TestCompareEntityNotEqual()
 {
     Customer alfki = new Customer { CustomerID = "ALFKI" };
     var list = db.Customers.Where(c => c != alfki);
     AssertValue(90, list.Count());
 }
 public virtual void TestCompareEntityEqual()
 {
     Customer alfki = new Customer { CustomerID = "ALFKI" };
     var list = db.Customers.Where(c => c == alfki).ToList();
     AssertValue(1, list.Count);
     AssertValue("ALFKI", list[0].CustomerID);
 }
Exemple #7
0
        //主键是自动增一的实体插入(Oracle数据表通过序列和触发器的方式,约定的Oracle序列必须是全局的,序列名称是:NEXTID
        public void InsertWithPrimaryKey_IsDbGenerated()
        {
            //1. 创建PO对象
            Customer c = new Customer
            {
                CustomerID = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City = "Seattle",
                Country = "USA"
            };

            var order = new Order
            {
                CustomerID = c.CustomerID,
                OrderDate = DateTime.Now,
            };

            //2. 创建DbContext 对象
            using (var db = cfg.CreateDbContext())
            {
                //3. 创建DbSet对象
                var cusotmers = db.Set<Customer>();
                var orders = db.Set<Order>();

                //4. 删除所有以“XX”开头的CustomerID记录
                orders.Delete(p => p.CustomerID.StartsWith("XX"));
                cusotmers.Delete(p => p.CustomerID.StartsWith("XX"));

                //在订单插入前,OrderId= 0
                Assert.IsTrue(order.OrderID == 0);

                //5. 执行PO插入
                cusotmers.Insert(c);
                orders.Insert(order);

                //在订单插入前,OrderId> 0
                Assert.IsTrue(order.OrderID > 0);

                orders.Delete(order);
                cusotmers.Delete(c);
            }
        }
Exemple #8
0
        public void DeleteByPO()
        {
            //1. 创建PO对象
            Customer c = new Customer
            {
                CustomerID = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City = "Seattle",
                Country = "USA"
            };

            //2. 创建DbContext 对象
            using (var db = cfg.CreateDbContext())
            {
                //3. 创建DbSet对象
                var cusotmers = db.Set<Customer>();

                //4. 删除所有以“XX”开头的CustomerID记录
                cusotmers.Delete(p => p.CustomerID.StartsWith("XX"));

                //5. 执行PO插入
                cusotmers.Insert(c);
                //6. 删除PO对象
                cusotmers.Delete(c);
            }
        }
Exemple #9
0
        public void DeleteByID_with_NameValueCollection()
        {
            //1. 创建PO对象
            Customer c = new Customer
            {
                CustomerID = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City = "Seattle",
                Country = "USA"
            };

            //2. 创建DbContext 对象
            using (var db = cfg.CreateDbContext())
            {
                //3. 创建DbSet对象
                var cusotmers = db.Set<Customer>();

                //4. 删除所有以“XX”开头的CustomerID记录
                cusotmers.Delete(p => p.CustomerID.StartsWith("XX"));

                //5. 执行PO插入
                cusotmers.Insert(c);
                //6. 通过CustomerID 进行删除
                var dict = new NameValueCollection();
                dict["customerId"] = c.CustomerID;

                cusotmers.Delete(dict);
            }
        }