Esempio n. 1
0
 public int Add(Person model)
 {
     StringBuilder strSql = new StringBuilder();
     strSql.Append("insert into Person(");
     strSql.Append("username,password,age,registerDate,address)");
     strSql.Append(" values (");
     strSql.Append("@username,@password,@age,@registerDate,@address)");
     //
     DbHelperSql.Insert(strSql.ToString(), model);
     //
     DbHelperSql.InsertReturnId(strSql.ToString(), model);
     //
     var mList=new List<Person>();
     mList.Add(new Person() {age = 1});
     mList.Add(new Person() {age = 1});
     mList.Add(new Person() {age = 1});
     DbHelperSql.InsertBatch(strSql.ToString(), mList);
     //
     var modeList = new List<Person>();
     for (int i = 0; i < 1000000; i++)
     {
         modeList.Add(new Person() {age = i,username = "******",address = "address",password = "******" });
     }
     DbHelperSql.InsertBatchBySqlBulkCopy(modeList);
     //
     return 1;
 }
Esempio n. 2
0
 public int Count(Person model, string where)
 {
     StringBuilder strSql = new StringBuilder();
     strSql.Append("select  count(*) from Person");
     strSql.Append(" where 1=1 and ");
     strSql.Append(where);
     var result = DbHelperSql.Count(strSql.ToString(), model);
     return result;
 }
Esempio n. 3
0
 public Person FindById(int id,int top=1)
 {
     //默认top 1--1条记录
     var model = new Person {id = id};
     StringBuilder strSql = new StringBuilder();
     strSql.AppendFormat("select  top {0} id,username,password,age,registerDate,address from Person ",top);
     strSql.Append(" where id=@id");
     //
     var result = DbHelperSql.Find(strSql.ToString(), model);
     return result;
 }
Esempio n. 4
0
 public IList<Person> FindList(Person model,string where,string orderBy, int pageIndex,int pageSize)
 {
     var startIndex = pageIndex*pageSize;
     var size = pageSize;
     StringBuilder strSql = new StringBuilder();
     strSql.Append("select  id,username,password,age,registerDate,address from Person ");
     strSql.Append(" where 1=1 and ");
     strSql.Append(where);
     strSql.AppendFormat("ORDER BY {0} OFFSET {1} ROWS FETCH NEXT {2} ROWS ONLY",orderBy,startIndex,size);
     var result = DbHelperSql.FindList(strSql.ToString(), model);
     return result;
 }
Esempio n. 5
0
 public int Update(Person model)
 {
     StringBuilder strSql = new StringBuilder();
     strSql.Append("update Person set ");
     strSql.Append("username=@username,");
     strSql.Append("password=@password,");
     strSql.Append("age=@age,");
     strSql.Append("registerDate=@registerDate,");
     strSql.Append("address=@address");
     strSql.Append(" where id=@id");
     //
     DbHelperSql.Update(strSql.ToString(), model);
     return 1;
 }
Esempio n. 6
0
        static void Test_Set()
        {
            //
            var person = new Person
            {
                username = "******"
            };

            var dao=new PersonDao();
            dao.Count(new Person(), "1=1");
            dao.FindList(new Person(), "1=1", "id", 0, 3);
            dao.FindById(7);
            dao.Update(person);
            dao.UpdateById(person,7);
            dao.DeleteById(5);
            //批量插入等
            //var id = new PersonDao().Add(person);
        }