Ejemplo n.º 1
0
        public void TestD_StoredProcedure2()
        {
            //存储过程,根据存储名称调用存储过程
            var result = DbHelp.ExecuteSql("delete_data", new { startId = 6 }, SugarCommandType.StoredProcedure);

            Assert.AreEqual(0, result, "调用存储过程错误");
        }
Ejemplo n.º 2
0
        public void TestC_Query4()
        {
            //带条件查询多个对象
            var result = DbHelp.QueryList <EmployeeModel>("select * from employee e where e.Status=20 and", new { e_Age_ge = 48 }, SugarCommandType.QuerySelectSql).ToList();

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

            Assert.AreEqual(1, result[0].Id, "带条件查询多个对象错误");
        }
Ejemplo n.º 3
0
        public void TestC_QueryPaging2()
        {
            //带条件查询多个对象
            var result = DbHelp.QueryPagingList2 <EmployeeModel>(1, 2, "select * from employee e where e.Status>0 and", new { e_Id_ue = 1 }, SugarCommandType.QuerySelectSql);

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

            Assert.AreEqual(4, result.List.FirstOrDefault().Id, "带条件查询多个对象错误");
        }
Ejemplo n.º 4
0
        public void TestC_Query2()
        {
            //查询多个对象
            var result = DbHelp.QueryList <EmployeeModel>("employee", new { Age_ge = 50, Age_le = 50 }, SugarCommandType.QueryTableDirect).ToList();

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

            Assert.AreEqual(1, result[0].Id, "查询多个对象");
        }
Ejemplo n.º 5
0
        public void TestD_StoredProcedure1()
        {
            //存储过程,根据存储名称调用存储过程
            var p = new DynamicParameters();

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

            var result = DbHelp.ExecuteSql("delete_data", p, SugarCommandType.StoredProcedure);

            Assert.AreEqual(7, result, "调用存储过程错误" + result);
        }
Ejemplo n.º 6
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.QueryList <EmployeeModel>("select * from employee e where", param, SugarCommandType.QuerySelectSql).ToList();

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

            Assert.AreEqual(2, result[0].Id, "别名查询多个对象错误");
        }
Ejemplo n.º 7
0
        public void TestC_Query1()
        {
            //查询单个对象
            var result = DbHelp.QuerySingle <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);

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

            Assert.AreEqual(2, result.Id, "查询单个对象");
        }
Ejemplo n.º 8
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.ExecuteSql("employee", employeeList, SugarCommandType.UpdateTableDirect);

                var addlist = DbHelp.DbProvider.QueryList <EmployeeModel>(conn, "employee", new { Id = new int[] { 1, 2 } }, SugarCommandType.QueryTableDirect, "Order By Id Asc").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
                              , "修改-表名-多个实体对象");
            }
        }
Ejemplo n.º 9
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.ExecuteSqlTran(commands);

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