コード例 #1
0
        public void TestD_Delete2()
        {
            //存储过程,根据存储名称调用存储过程
            var result = DbHelp.ExecuteSqlAsync("delete from employee where Id > @startId", new { startId = 6 }, SugarCommandType.Text).Result;

            Assert.AreEqual(result, 0, "调用删除错误");
        }
コード例 #2
0
        public void TestC_QueryPaging2()
        {
            //带条件查询多个对象
            var result = DbHelp.QueryPagingListAsync2 <EmployeeModel>(1, 2, "select * from employee e where e.Status>0 and", new { e_Id_ue = 1 }, SugarCommandType.QuerySelectSql).Result;

            Assert.AreEqual(2, result.List.Count(), "带条件查询多个对象错误");

            Assert.AreEqual(4, result.List.FirstOrDefault().Id, "带条件查询多个对象错误");
        }
コード例 #3
0
        public void TestC_Query2()
        {
            //查询多个对象
            var result = (DbHelp.QueryListAsync <EmployeeModel>("employee", new { Age_ge = 50, Age_le = 50 }, SugarCommandType.QueryTableDirect)).Result.ToList();

            Assert.AreEqual(1, result.Count, "查询多个对象");

            Assert.AreEqual(1, result[0].Id, "查询多个对象");
        }
コード例 #4
0
        public void TestC_Query4()
        {
            //带条件查询多个对象
            var result = (DbHelp.QueryListAsync <EmployeeModel>("select * from employee e where e.Status=20 and", new { e_Age_ge = 48 }, SugarCommandType.QuerySelectSql)).Result.ToList();

            Assert.AreEqual(1, result.Count, "带条件查询多个对象错误");

            Assert.AreEqual(1, result[0].Id, "带条件查询多个对象错误");
        }
コード例 #5
0
        public void TestD_Delete1()
        {
            //存储过程,根据存储名称调用存储过程
            var p = new DynamicParameters();

            p.Add("@startId", 6);

            var result = DbHelp.ExecuteSqlAsync("delete from employee where Id > @startId", p, SugarCommandType.Text).Result;

            Assert.AreEqual(result, 7, "调用删除错误");
        }
コード例 #6
0
        public void TestD_Delete1()
        {
            //存储过程,根据存储名称调用存储过程
            var p = new DynamicParameters();

            p.Add("@startId", 6, System.Data.DbType.Int32, System.Data.ParameterDirection.Input);

            var result = DbHelp.ExecuteSql("delete from employee where Id > @startId", p, SugarCommandType.Text);

            Assert.AreEqual(result, 7, "调用删除错误");
        }
コード例 #7
0
        public void TestC_Query3()
        {
            //别名查询多个对象
            //new { ue_e_Id = 1, ge_e_Age = 48 }
            var param = new { e_Id_ue = 1, e_Age_ge = 48 };
            //dynamic param = new ExpandoObject();
            //param.e_Age_ge = 48;
            //param.ue_e_Id = 1;
            //param.ge_e_Age = 48;
            var result = (DbHelp.QueryListAsync <EmployeeModel>("select * from employee e where", param, SugarCommandType.QuerySelectSql)).Result.ToList();

            Assert.AreEqual(1, result.Count, "别名查询多个对象错误");

            Assert.AreEqual(2, result[0].Id, "别名查询多个对象错误");
        }
コード例 #8
0
        public void TestC_Query1()
        {
            //查询单个对象
            var result = DbHelp.QuerySingleAsync <EmployeeModel>("employee", new
            {
                ig_Account = "lujunyi",
                sq_Account = "Account=@ig_Account",
                Name_lk    = "卢%",
                Status     = new int[] { 10 },
                Age_gt     = 47,
                Age_lt     = 49,
            }, SugarCommandType.QueryTableDirect).Result;

            Assert.IsNotNull(result, "查询单个对象");

            Assert.AreEqual(2, result.Id, "查询单个对象");
        }
コード例 #9
0
        public void TestB_Update2()
        {
            var employeeList = new List <EmployeeModel>
            {
                new EmployeeModel
                {
                    Id      = 1,
                    Account = "songjiang",
                    Name    = "宋江",
                    Age     = 50,
                    Status  = EmployeeModel.EnumStatus.Complate
                },
                new EmployeeModel
                {
                    Id      = 2,
                    Account = "lujunyi",
                    Name    = "卢俊义",
                    Age     = 48,
                    Status  = EmployeeModel.EnumStatus.Disable
                }
            };

            using (var conn = DbHelp.DbProvider.CreateConnection())
            {
                var result = DbHelp.ExecuteSqlAsync("employee", employeeList, SugarCommandType.UpdateTableDirect).Result;

                var addlist = (DbHelp.DbProvider.QueryListAsync <EmployeeModel>(conn, "employee", new { Id = new int[] { 1, 2 } }, SugarCommandType.QueryTableDirect, "Order By Id Asc")).Result.ToList();

                Assert.AreEqual(2, result, "修改-表名-多个实体对象");

                Assert.IsTrue(addlist.Count == 2 &&
                              addlist[0].Account == employeeList[0].Account &&
                              addlist[0].Name == employeeList[0].Name &&
                              addlist[0].Age == employeeList[0].Age &&
                              addlist[0].Status == employeeList[0].Status

                              && addlist[1].Account == employeeList[1].Account &&
                              addlist[1].Name == employeeList[1].Name &&
                              addlist[1].Age == employeeList[1].Age &&
                              addlist[1].Status == employeeList[1].Status
                              , "修改-表名-多个实体对象");
            }
        }
コード例 #10
0
        public void TestB_Update3()
        {
            var employeeList = new List <EmployeeModel>
            {
                new EmployeeModel
                {
                    Id      = 1,
                    Account = "songjiang",
                    Name    = "宋江",
                    Age     = 50,
                    Status  = EmployeeModel.EnumStatus.Complate
                },
                new EmployeeModel
                {
                    Id      = 2,
                    Account = "lujunyi",
                    Name    = "卢俊义",
                    Age     = 48,
                    Status  = EmployeeModel.EnumStatus.Disable
                }
            };

            List <object> paramList = new List <object>();

            foreach (var item in employeeList)
            {
                paramList.Add(new { Id = item.Id, Account = item.Account });
            }

            CommandCollection commands = new CommandCollection();

            commands.Add("employee", paramList, SugarCommandType.UpdateTableDirect);
            commands.Add("employee", list.Skip(2).Take(2).Select(t => new { Id = t.Id, Account = t.Account }).ToArray(), SugarCommandType.UpdateTableDirect);

            bool result = DbHelp.ExecuteSqlTranAsync(commands).Result;

            Assert.IsTrue(result, "修改-表名-多个匿名实体对象");
        }