Exemple #1
0
        /// <summary>
        /// 单表操作,一次性存储多条数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="ctrl"></param>
        /// <param name="data"></param>
        public static ActionResult <int> SaveData <T>(this IData instance, T[] data, int[][] columns = null)
        {
            IDBHelper db = DbFactory.Execute();

            db.BeginTransaction();
            var i = 0;

            foreach (T t in data)
            {
                int[] column;
                try
                {
                    column = columns[i];
                }
                catch (Exception e)
                {
                    return(ActionResult <int> .SetError(e.Message, -1));
                }
                var sqlCommand = new SqlExpression().Insert <T>().Values(column, t);

                try
                {
                    db.ExecuteNonQuery(sqlCommand.Command, CommandType.Text, sqlCommand.ToParameters());
                }
                catch (Exception e)
                {
                    return(ActionResult <int> .SetError(e.Message, -1));
                }
                i++;
            }
            db.Commit();
            return(ActionResult <int> .SetSuccess("Saved successful."));
        }
Exemple #2
0
        public void BegionTransaction()
        {
            IDBHelper _DBHelper = null;

            try
            {
                _DBHelper = CreateHelper();
                _DBHelper.BeginTransaction();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #3
0
 public void Begin()
 {
     _iHelper.BeginTransaction();
 }