Beispiel #1
0
        public void BaseDelete()
        {
            var data = new StudentDto
            {
                Score      = 50.5,
                StuGender  = true,
                CreateTime = DateTime.Now,
                Version    = Guid.NewGuid().ToString("N"),
                StuName    = "zs",
            };
            var id = _context.From <StudentDto>().InsertReturnId(data);

            _context.From <StudentDto>().Delete(a => a.Id == id);
            var flag = _context.From <StudentDto>().Exists(a => a.Id == id);

            Assert.False(flag);
        }
Beispiel #2
0
        public void ExecuteSql()
        {
            var data = new StudentDto
            {
                Score      = 50.5,
                StuGender  = true,
                CreateTime = DateTime.Now,
                Version    = Guid.NewGuid().ToString("N"),
                StuName    = "zs",
            };
            var sql = @"INSERT INTO student
                (stu_name,stu_gender,score,version,create_time) values 
                (@StuName,@StuGender,@Score,@Version,@CreateTime)";
            var row = _context.Execute(sql, data);

            Assert.Equal(1, row);
        }
Beispiel #3
0
        public void ExpressionUpdate()
        {
            var data = new StudentDto
            {
                Score      = 50.5,
                StuGender  = true,
                CreateTime = DateTime.Now,
                Version    = Guid.NewGuid().ToString("N"),
                StuName    = "zs",
            };
            var id  = _context.From <StudentDto>().InsertReturnId(data);
            var row = _context.From <StudentDto>()
                      .Set(a => a.Score, a => a.Score + 0.5)
                      .Where(a => a.Id == id)
                      .Update();
            var entity = _context.From <StudentDto>().Where(a => a.Id == id).Single();

            Assert.Equal(entity.Score, data.Score + 0.5);
        }
Beispiel #4
0
        public void BaseUpdate()
        {
            var data = new StudentDto
            {
                Score      = 50.5,
                StuGender  = true,
                CreateTime = DateTime.Now,
                Version    = Guid.NewGuid().ToString("N"),
                StuName    = "zs",
            };

            _context.From <StudentDto>().Insert(data);
            var entity = _context.From <StudentDto>().Where(a => a.Version == data.Version).Single();

            entity.Score     = 1;
            entity.StuName   = "BaseUpdate";
            entity.StuGender = false;
            var row = _context.From <StudentDto>().Update(entity);

            Assert.Equal(1, row);
        }