Exemple #1
0
        public void SimpleUpdateExpressionMethodTest2()
        {
            using (var connect = GetOpenConnection())
            {
                // 匿名对象1
                var entity1 = new { CustomerName = "hello", CustomerCity = "x1" };

                var updater1 = connect.Update <CustomersEntity>(entity1)
                               .Where(c => c.CustomerID == 2);

                string sql1 = updater1.SQL;
                Assert.Equal(sql1,
                             "Update Customers2 SET CustomerName=@CustomerName,CustomerCity=@CustomerCity Where CustomerID = 2");

                // 匿名对象2
                CustomersEntity entity2 = new CustomersEntity {
                    CustomerName = "hello", CustomerCity = "x1", CustomerNumber = "x123"
                };

                var updater2 = connect.Update <CustomersEntity>(new { entity2.CustomerName, entity2.CustomerCity })
                               .Where(c => c.CustomerID == 2);

                string sql2 = updater2.SQL;
                Assert.Equal(sql2,
                             "Update Customers2 SET CustomerName=@CustomerName,CustomerCity=@CustomerCity Where CustomerID = 2");

                // 实体对象/全字段更新且忽略标记了Computed特性的属性
                var updater3 = connect.Update <CustomersEntity>(entity2)
                               .Where(c => c.CustomerID == 2);
                string sql3 = updater3.SQL;
            }
        }
Exemple #2
0
        public void SetActiveTest2()
        {
            using (var connect = GetOpenConnection())
            {
                var customer = new CustomersEntity()
                {
                    CustomerID = 2, IsActive = false
                };
                bool s = connect.SetActive(customer);

                Assert.Equal(s, true);
            }
        }
Exemple #3
0
        public void UpdateCustomer()
        {
            using (var connect = GetOpenConnection())
            {
                var customer = new CustomersEntity()
                {
                    CustomerID = 1, CustomerName = "A1", CustomerCity = "x1", CustomerNumber = "9999"
                };
                //更新实体,不能只更新某些字段
                bool s = connect.Update(customer);

                Assert.Equal(s, true);
            }
        }
Exemple #4
0
        public void QueryWithSortCustomer()
        {
            CustomersEntity entity = null;
            DapperSort      sort   = new DapperSort()
            {
                new Sort(index: 1, field: nameof(entity.CustomerCity), sortType: ESortType.Asc),
                new Sort(index: 0, field: nameof(entity.CustomerName), sortType: ESortType.Desc)
            };

            using (var connect = GetOpenConnection())
            {
                var customer = connect.Query <CustomersEntity>(c => c.CustomerID == 1, null, sort);
            }
        }
Exemple #5
0
        public void InsertCustomer()
        {
            using (var connect = GetOpenConnection())
            {
                int count = connect.QuerySingle <int>("select count(1) from Customers2");


                var customer = new CustomersEntity()
                {
                    CustomerName = "A1", CustomerCity = "x1", CustomerNumber = "9999"
                };

                long id = connect.Insert(customer);

                Assert.Equal(id - 2, count);
            }
        }