예제 #1
0
        public static int InsertList <T>(this IDbConnection db, IEnumerable <T> entitys, IDbTransaction trans = null, int?commandTimeout = null)
        {
            if (!entitys.Any())
            {
                return(0);
            }

            var sqllam = new SqlExp <T>(db.GetAdapter());

            sqllam = sqllam.Insert();
            var sqlString = sqllam.SqlString;

            try
            {
                DebuggingSqlString(sqlString);

                return(db.Execute(sqlString, entitys, trans, commandTimeout, CommandType.Text));
            }
            catch (Exception ex)
            {
                DebuggingException(ex, sqlString);
                throw new DapperLamException(ex.Message, ex, sqlString)
                      {
                          Parameters = sqllam.Parameters
                      };
            }
        }
예제 #2
0
        public static int Insert <T>(this IDbConnection db, T entity, IDbTransaction trans = null, int?commandTimeout = null)
        {
            var sqllam = new SqlExp <T>(db.GetAdapter());


            sqllam = sqllam.Insert();

            try
            {
                return(db.Execute(sqllam.SqlString, entity, trans, commandTimeout, CommandType.Text));
            }
            catch (Exception ex)
            {
                if (Debugger.IsAttached)
                {
                    Debug.WriteLine(ex.Message + ex.StackTrace);
                    Debug.WriteLine(sqllam.SqlString);
                }

                Console.WriteLine(ex.Message + ex.StackTrace);
                Console.WriteLine(sqllam.SqlString);
                throw new DapperLamException(ex.Message, ex, sqllam.SqlString)
                      {
                          Parameters = sqllam.Parameters
                      };
            }
        }
예제 #3
0
        public static int Insert(this IDbConnection db, SqlTableDefine tableDefine, List <SqlColumnDefine> columnDefines, IEnumerable <object> entity, IDbTransaction trans = null, int?commandTimeout = null)
        {
            var sqllam = new SqlExp <object>(tableDefine, columnDefines, db.GetAdapter());

            sqllam = sqllam.Insert(tableDefine, columnDefines);
            var sqlString = sqllam.SqlString;

            try
            {
                DebuggingSqlString(sqlString);
                return(db.Execute(sqlString, entity, trans, commandTimeout, CommandType.Text));
            }
            catch (Exception ex)
            {
                DebuggingException(ex, sqlString);
                throw new DapperLamException(ex.Message, ex, sqlString)
                      {
                          Parameters = sqllam.Parameters
                      };
            }
        }
예제 #4
0
        public static Task <int> InsertAsync <T>(this IDbConnection db, T entity, IDbTransaction trans = null,
                                                 int?commandTimeout = null)
        {
            var sqllam = new SqlExp <T>(db.GetAdapter());

            sqllam = sqllam.Insert();
            var sqlString = sqllam.SqlString;

            try
            {
                DebuggingSqlString(sqlString);
                return(db.ExecuteAsync(sqlString, entity, trans, commandTimeout, CommandType.Text));
            }
            catch (Exception ex)
            {
                DebuggingException(ex, sqlString);
                throw new DapperLamException(ex.Message, ex, sqlString)
                      {
                          Parameters = sqllam.Parameters
                      };
            }
        }