Example #1
0
 public void Insert_Normal()
 {
     var insertUser = new InsertUserVO() { PassWord = "******", UserName = "******" };
     // 存储过程
     Table.Data.InsertUser.Execute(insertUser);
     Assert.IsTrue(insertUser.ID > 0);
 }
Example #2
0
 public void Insert_Transaction()
 {
     using (var context = new Table())
     {
         var insertUser = new InsertUserVO() { PassWord = "******", UserName = "******" };
         // 存储过程
         context.InsertUser.Execute(insertUser);
         Assert.IsTrue(insertUser.ID > 0);
         context.SaveChanges();
     }
 }
Example #3
0
        public void Transaction_Insert()
        {
            using (var context = new Table())
            {
                int ID;
                var userInfo = new UserVO() {UserName = "******", GetDate = DateTime.Now};
                var insertUser = new InsertUserVO() {PassWord = "******", UserName = "******"};

                // 将标识设置到标识字段
                context.User.Insert(userInfo, true);
                Assert.IsTrue(userInfo.ID > 0);

                // 设置out ID
                userInfo.ID++;
                context.User.Insert(userInfo, out ID);
                Assert.IsTrue(userInfo.ID > 0 && userInfo.ID == ID);

                // 缓存表
                context.UserRole.Insert(new UserRoleVO {Caption = "标题", Descr = "不清楚"});

                // 不同逻辑删除方式新入(主键为GUID)
                context.Orders.Insert(new OrdersVO {ID = Guid.NewGuid(), OrderNo = "12345678-1", CreateAt = DateTime.Now, CreateName = "用户1"});
                context.OrdersAt.Insert(new OrdersVO {ID = Guid.NewGuid(), OrderNo = "12345678-2", CreateAt = DateTime.Now, CreateName = "用户1"});
                context.OrdersBool.Insert(new OrdersVO {ID = Guid.NewGuid(), OrderNo = "12345678-3", CreateAt = DateTime.Now, CreateName = "用户1"});
                context.OrdersNum.Insert(new OrdersVO {ID = Guid.NewGuid(), OrderNo = "12345678-4", CreateAt = DateTime.Now, CreateName = "用户1"});
                context.OrdersBoolCache.Insert(new OrdersVO {ID = Guid.NewGuid(), OrderNo = "12345678-5", CreateAt = DateTime.Now, CreateName = "用户1"});

                // 存储过程
                Table.TransactionInstance(context).InsertUser.Execute(insertUser);
                Assert.IsTrue(insertUser.ID > 0);

                // 配置SQL
                Table.TransactionInstance(context).InsertNewUser.Execute();

                // 手动SQL
                var table = Table.TransactionInstance(context);
                table.ManualSql.Execute("INSERT INTO Members_User (UserName,PassWord) VALUES(@UserName,@PassWord)", table.DbProvider.CreateDbParam("UserName", "steden1"), table.DbProvider.CreateDbParam("PassWord", "steden1"));

                context.SaveChanges();
            }
        }