Exemplo n.º 1
0
        /// <summary>
        /// 根据条件以及指定属性名称更新
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="connection"></param>
        /// <param name="entity"></param>
        /// <param name="condition"></param>
        /// <param name="transaction"></param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        public int Update <T>(IDbConnection connection, T entity, Expression <Func <T, bool> > condition, IDbTransaction transaction = null, int?timeout = Timeout) where T : class
        {
            int res = 0;

            this.Logger(this.GetType(), "根据条件以及指定属性名称更新-Update", () =>
            {
                LambdaExpConditions <T> lambda = new LambdaExpConditions <T>();
                lambda.AddAndWhere(condition);
                string where = lambda.Where();

                string sql = DatabaseCommon.UpdateSql <T>(entity, "", where).ToString();
                res        = connection.Execute(sql, entity, transaction, timeout);
            }, e =>
            {
                if (transaction != null)
                {
                    transaction.Rollback();
                }

                connection.Close();
                connection.Dispose();
            }, () =>
            {
            });
            return(res);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 根据条件以及指定属性名称更新
        /// </summary>
        /// <typeparam name="T">动态对象</typeparam>
        /// <param name="entity">待更新实体</param>
        /// <param name="condition">筛选条件</param>
        /// <param name="timeout">超时时间</param>
        /// <returns></returns>
        public int Update <T>(object entity, Expression <Func <T, bool> > condition, int?timeout = Timeout) where T : IEntity
        {
            int res = 0;

            this.Logger(this.GetType(), "根据条件以及指定属性名称更新-Update", () =>
            {
                if (entity != null)
                {
                    LambdaExpConditions <T> lambda = new LambdaExpConditions <T>();
                    lambda.AddAndWhere(condition);
                    string where = lambda.Where();
                    string sql   = DatabaseCommon.UpdateSql <T>(entity, "", where).ToString();

                    if (this.BaseDbTransaction == null)
                    {
                        using (IDbConnection connection = this.BaseDbConnection)
                        {
                            res = connection.Execute(sql, entity, null, timeout, CommandType.Text);
                        }
                    }
                    else
                    {
                        res = this.BaseDbTransaction.Connection.Execute(sql, entity, this.BaseDbTransaction, timeout, CommandType.Text);
                    }
                }
            }, e =>
            {
                this.Rollback();
            });
            return(res);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <typeparam name="T">动态对象</typeparam>
        /// <param name="entity">待更新实体</param>
        /// <param name="timeout">超时时间</param>
        /// <returns></returns>
        public int Update <T>(object entity, int?timeout = Timeout) where T : IEntity
        {
            int res = 0;

            this.Logger(this.GetType(), "更新-Update", () =>
            {
                if (entity != null)
                {
                    string sql = DatabaseCommon.UpdateSql <T>(entity).ToString();

                    if (this.BaseDbTransaction == null)
                    {
                        using (IDbConnection connection = this.BaseDbConnection)
                        {
                            res = connection.Execute(sql, entity, null, timeout, CommandType.Text);
                        }
                    }
                    else
                    {
                        res = this.BaseDbTransaction.Connection.Execute(sql, entity, this.BaseDbTransaction, timeout, CommandType.Text);
                    }
                }
            }, e =>
            {
                this.Rollback();
            });
            return(res);
        }
Exemplo n.º 4
0
        /// <summary>
        ///更新
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Update <T>(T entity) where T : class
        {
            string sql = DatabaseCommon.UpdateSql <T>(entity).ToString();

            //DbParameter[] parameter = DatabaseCommon.GetParameter<T>(entity);

            return(ExecuteBySql(sql, entity));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 根据条件以及指定属性名称更新
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="modelModifyProps"></param>
        /// <param name="condition"></param>
        /// <returns></returns>
        public int Update <T>(T modelModifyProps, Expression <Func <T, bool> > condition) where T : class, new()
        {
            int res = 0;

            LambdaExpConditions <T> lambda = new LambdaExpConditions <T>();

            lambda.AddAndWhere(condition);
            string where = lambda.Where();

            string sql = DatabaseCommon.UpdateSql <T>(modelModifyProps, "", where).ToString();

            //DbParameter[] parameter = DatabaseCommon.GetParameter<T>(modelModifyProps);

            res = ExecuteBySql(sql, modelModifyProps);

            return(res);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="connection"></param>
        /// <param name="entity"></param>
        /// <param name="transaction"></param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        public int Update <T>(IDbConnection connection, T entity, IDbTransaction transaction = null, int?timeout = Timeout) where T : class
        {
            int res = 0;

            this.Logger(this.GetType(), "更新-Update", () =>
            {
                string sql = DatabaseCommon.UpdateSql <T>(entity).ToString();
                res        = connection.Execute(sql, entity, transaction, timeout);
            }, e =>
            {
                if (transaction != null)
                {
                    transaction.Rollback();
                }

                connection.Close();
                connection.Dispose();
            }, () =>
            {
            });
            return(res);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="entity">实体对象</param>
        /// <returns></returns>
        public int Update <T>(T entity) where T : class
        {
            int res = 0;

            if (SqlTransaction == null)
            {
                string        sql       = DatabaseCommon.UpdateSql <T>(entity).ToString();
                DbParameter[] parameter = DatabaseCommon.GetParameter <T>(entity);

                using (var conn = Connection)
                {
                    res = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql, DatabaseCommon.DbParameterToSqlParameter(parameter));
                }
            }
            else
            {
                string        sql       = DatabaseCommon.UpdateSql <T>(entity).ToString();
                DbParameter[] parameter = DatabaseCommon.GetParameter <T>(entity);

                res = SqlHelper.ExecuteNonQuery(SqlTransaction, CommandType.Text, sql, DatabaseCommon.DbParameterToSqlParameter(parameter));
            }
            return(res);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 根据条件更新
        /// </summary>
        /// <param name="modelModifyProps">要修改的列及修改后列的值集合</param>
        /// <param name="condition">修改的条件</param>
        /// <returns>返回受影响行数</returns>
        public int Update <T>(T modelModifyProps, Expression <Func <T, bool> > condition) where T : class, new()
        {
            int res = 0;
            LambdaExpConditions <T> lambda = new LambdaExpConditions <T>();

            lambda.AddAndWhere(condition);
            string where = lambda.Where();
            string sql = DatabaseCommon.UpdateSql <T>(modelModifyProps, "", where).ToString();

            if (SqlTransaction == null)
            {
                using (var conn = Connection)
                {
                    res = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql);
                }
            }
            else
            {
                res = SqlHelper.ExecuteNonQuery(SqlTransaction, CommandType.Text, sql);

                //res = this.Commit();
            }
            return(res);
        }
Exemplo n.º 9
0
 public int Update <T>(T entity) where T : class
 {
     return(ExecuteBySql(DatabaseCommon.UpdateSql <T>(entity).ToString(), DatabaseCommon.GetParameter <T>(entity)));
 }
Exemplo n.º 10
0
 public int UpdateNew <T>(T entity, bool isBatch = false) where T : class
 {
     return(ExecuteBySql(DatabaseCommon.UpdateSql <T>(entity).ToString(), DatabaseCommon.GetParameter <T>(entity)));
 }
Exemplo n.º 11
0
 public int Update <T>(T entity, string pkName) where T : class
 {
     return(ExecuteNonQuery(DatabaseCommon.UpdateSql <T>(entity, pkName).ToString(), DatabaseCommon.GetParameter <T>(entity)));
 }