示例#1
0
        public static int UpdateList <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.Update();
            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
                      };
            }
        }
        public static int Update <T>(this IDbConnection con, T entity, Expression <Func <T, bool> > whereExpression, IDbTransaction trans = null, int?commandTimeout = null)
        {
            var db = trans == null ? con : trans.Connection;

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

            sqllam = sqllam.Update();

            if (whereExpression != null)
            {
                sqllam.Where(whereExpression);
            }

            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
                      };
            }
        }
示例#3
0
        public static Task <int> UpdateAsync <T>(this IDbConnection con, T entity, IDbTransaction trans = null,
                                                 int?commandTimeout = null)
        {
            var db = con;

            if (trans != null)
            {
                db = trans.Connection;
            }

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


            sqllam = sqllam.Update();
            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
                      };
            }
        }
示例#4
0
        public static int Update <T>(this IDbConnection db, T entity, IDbTransaction trans = null, int?commandTimeout = null)
        {
            var sqllam = new SqlExp <T>(db.GetAdapter());


            sqllam = sqllam.Update();

            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
                      };
            }
        }