Exemplo n.º 1
0
        /// <summary>
        /// 指定更新的列和值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="kvs">要更新的列和值</param>
        /// <param name="msu">要更新的数据条件</param>
        /// <returns></returns>
        public int Set <T>(KeyValuePairs kvs, MySearchUtil msu)
        {
            DynamicParameters param = new DynamicParameters();
            List <string>     props = new List <string>();

            foreach (var kv in kvs)
            {
                props.Add(kv.Key);
                param.Add(kv.Key, kv.Value);
            }

            var sql = MyContainer.Get(typeof(T)).GetUpdateSql(props.ToArray(), null, msu.ConditionClaus);

            using (var conn = GetConnection())
            {
                return(conn.Execute(sql, param));
            }
        }
Exemplo n.º 2
0
 public int Update(KeyValuePairs cols, string table, MySearchUtil util)
 {
     using (var conn = GetConnection())
     {
         var           _params      = util.GetParameters();
         List <string> _update_cols = new List <string>();
         int           idx          = 0;
         string        _paramName   = "";
         foreach (var kv in cols)
         {
             _paramName = _paramPrefix + "c" + idx.ToString();
             _update_cols.Add(kv.Key + "=" + _paramName);
             _params.Add(_paramName, kv.Value);
             idx++;
         }
         string sql = "UPDATE [" + table + "] SET " + string.Join(",", _update_cols) + " WHERE " + util.GetConditionClaus();
         return(conn.Execute(sql, _params));
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// 执行事务
 /// </summary>
 /// <param name="sqls"></param>
 /// <returns></returns>
 public bool ExecuteTran(KeyValuePairs sqls)
 {
     using (var conn = GetConnection())
     {
         conn.Open();
         using (var tran = conn.BeginTransaction())
         {
             try
             {
                 foreach (var s in sqls)
                 {
                     conn.Execute(s.Key, s.Value, tran);
                 }
                 tran.Commit();
                 return(true);
             }
             catch
             {
                 tran.Rollback();
                 return(false);
             }
         }
     }
 }