Exemple #1
0
 public void GetByWhereFirst()
 {
     using (var conn = DbHelper.GetConn())
     {
         PeopleTable people = conn.GetByWhereFirst <PeopleTable>("WHERE Id<@Id", new { Id = 4 });
         //PeopleTable people = conn.GetByWhereFirst<PeopleTable>("WHERE Id<@Id", new { Id = 4 },"Name"); //only return [Name] field
         string json = JsonConvert.SerializeObject(people);
         Assert.Pass(json);
     }
 }
Exemple #2
0
 public void GetById()
 {
     using (var conn = DbHelper.GetConn())
     {
         PeopleTable people = conn.GetById <PeopleTable>(1);
         //PeopleTable people = conn.GetById<PeopleTable>(1,"Name"); //only return [name] field
         string json = JsonConvert.SerializeObject(people);
         Assert.Pass(json);
     }
 }
Exemple #3
0
 public void InsertReturnId()
 {
     using (var conn = DbHelper.GetConn())
     {
         PeopleTable people = new PeopleTable();
         people.Name = "李四" + Second;
         people.Sex  = Second;
         var id = conn.InsertReturnId(people);
         Assert.Pass(id.ToString());
     }
 }
Exemple #4
0
 public void InsertIdentity()
 {
     using (var conn = DbHelper.GetConn())
     {
         PeopleTable people = new PeopleTable();
         people.Id   = 1;
         people.Name = "李四" + Second;
         people.Sex  = Second;
         int effect = conn.InsertIdentity(people);
         Assert.Pass(effect.ToString());
     }
 }
Exemple #5
0
        public void UpdateByWhere()
        {
            using (var conn = DbHelper.GetConn())
            {
                PeopleTable people = new PeopleTable();
                people.Id   = 1;
                people.Name = "钱七" + Second;
                people.Sex  = 47;

                int effect = conn.UpdateByWhere(people, "WHERE Sex=@Sex", "Name"); //update people set Name=@Name WHERE Sex=@Sex
                Assert.Pass(effect.ToString());
            }
        }
Exemple #6
0
 public void Update()
 {
     using (var conn = DbHelper.GetConn())
     {
         PeopleTable people = new PeopleTable();
         people.Id   = 1;
         people.Name = "李四" + Second;
         people.Sex  = Second;
         int effect = conn.Update(people);
         //int effect = conn.Update(people, "Name"); //update people set Name=@Name where Id=@Id
         Assert.Pass(effect.ToString());
     }
 }
Exemple #7
0
        public void Insert()
        {
            using (var conn = DbHelper.GetConn())
            {
                PeopleTable people = new PeopleTable();
                people.Name = "李四" + Second;
                people.Sex  = Second;
                int effect = conn.Insert(people);

                StudentTable student = new StudentTable();
                student.Id   = ObjectId.GenerateNewId().ToString();
                student.Name = "王五" + Second;
                student.Sex  = Second;
                effect      += conn.Insert(student);
                Assert.Pass(effect.ToString());
            }
        }
Exemple #8
0
        public void InsertIdentityOrUpdate()
        {
            using (var conn = DbHelper.GetConn())
            {
                PeopleTable people = new PeopleTable();
                people.Id   = 1;
                people.Name = "王五" + Second;
                people.Sex  = Second;
                int effect = conn.InsertIdentityOrUpdate(people);

                PeopleTable p2 = new PeopleTable();
                p2.Id   = 52;
                p2.Name = "小罗" + Second;
                p2.Sex  = Second;
                effect += conn.InsertIdentityOrUpdate(p2);

                Assert.Pass(effect.ToString());
            }
        }
Exemple #9
0
        public void Insert()
        {
            using (var conn = DbHelper.GetConn())
            {
                PeopleTable people = new PeopleTable();
                people.Name = "李四" + Second;
                people.Sex  = Second;
                int effect = conn.InsertAsync(people).Result;

                StudentTable student = new StudentTable();
                student.Id   = ObjectId.GenerateNewId().ToString();
                student.Name = "王五" + Second;
                student.Sex  = Second;
                int effect2 = conn.InsertAsync(student).Result;

                string msg = string.Format("\n effect:{0} \n effsct2:{1}", effect, effect2);
                Assert.Pass(msg);
            }
        }
Exemple #10
0
        public void InsertOrUpdate()
        {
            using (var conn = DbHelper.GetConn())
            {
                PeopleTable people = new PeopleTable();
                people.Id   = 1;
                people.Name = "王五" + Second;
                people.Sex  = Second;

                PeopleTable p2 = new PeopleTable();
                p2.Id   = 2;
                p2.Name = "王五" + Second;
                p2.Sex  = Second;

                int effect = conn.InsertOrUpdate(people);
                //int effect = conn.InsertOrUpdate(people, "Name"); //only update Name
                effect += conn.InsertOrUpdate(p2);

                Assert.Pass(effect.ToString());
            }
        }