示例#1
0
        /// <summary>
        /// 根据条件更新实体信息(返回受影响行数)
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="lstColumns">实体列</param>
        /// <param name="lstIgnoreColumns">忽略列</param>
        /// <param name="strWhere">条件</param>
        /// <returns></returns>
        public int UpdateEx(TEntity entity, List <string> lstColumns = null, List <string> lstIgnoreColumns = null, string strWhere = "")
        {
            int result = 0;

            try
            {
                _db.Ado.BeginTran();
                IUpdateable <TEntity> up = _db.Updateable(entity);
                if (lstIgnoreColumns != null && lstIgnoreColumns.Count > 0)
                {
                    up = up.IgnoreColumns(lstIgnoreColumns.ToArray());
                }
                if (lstColumns != null && lstColumns.Count > 0)
                {
                    up = up.UpdateColumns(lstColumns.ToArray());
                }
                if (!string.IsNullOrEmpty(strWhere))
                {
                    up = up.Where(strWhere);
                }
                result = up.ExecuteCommand();
                _db.Ado.CommitTran();
            }
            catch (Exception)
            {
                _db.Ado.RollbackTran();
            }
            return(result);
        }
示例#2
0
        /// <summary>
        /// 功能描述:修改数据
        /// </summary>
        /// <param name="lstColumnValues">列,值</param>
        /// <param name="whereExpression">条件</param>
        /// <returns>是否成功</returns>
        public bool Update(Dictionary <string, object> lstColumnValues, Expression <Func <T, bool> > whereExpression)
        {
            IUpdateable <T> up = _db.Updateable <T>(lstColumnValues);

            if (whereExpression != null)
            {
                up = up.Where(whereExpression);
            }
            return(up.ExecuteCommand() > 0);
        }
示例#3
0
        /// <summary>
        /// 修改(主键是更新条件)
        /// </summary>
        /// <param name="entitys">实体对象集合(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]) </param>
        /// <param name="ignoreColumns">不更新的列</param>
        /// <returns>操作影响的行数</returns>
        public int Update(List <TEntity> entitys, string[] ignoreColumns = null)
        {
            IUpdateable <TEntity> up = _dbContext.Updateable(entitys);

            if (ignoreColumns != null && ignoreColumns.Length > 0)
            {
                up = up.IgnoreColumns(ignoreColumns);
            }
            return(up.ExecuteCommand());
        }
示例#4
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="update">实体对象</param>
        /// <param name="predicate">条件</param>
        /// <returns>操作影响的行数</returns>
        public int Update(Expression <Func <TEntity, TEntity> > update, Expression <Func <TEntity, bool> > predicate = null)
        {
            IUpdateable <TEntity> up = _dbContext.Updateable(update);

            if (predicate != null)
            {
                up = up.Where(predicate);
            }
            return(up.ExecuteCommand());
        }
示例#5
0
        public int UpDate(articulo lcs_Goods)
        {
            //using (var con = DbConfig.GetConnection())
            //{
            //    return con.Update<articulo>(lcs_Goods);
            //}
            IUpdateable <articulo> updateable = DbConfig.DB.Updateable <articulo>();

            return(updateable.ExecuteCommand());
        }
示例#6
0
        public Task <int> ExecuteCommandAsync()
        {
            Task <int> result = new Task <int>(() =>
            {
                IUpdateable <T> asyncUpdateable = CopyUpdateable();
                return(asyncUpdateable.ExecuteCommand());
            });

            result.Start();
            return(result);
        }
示例#7
0
        public Task <bool> ExecuteCommandHasChangeAsync()
        {
            Task <bool> result = new Task <bool>(() =>
            {
                IUpdateable <T> asyncUpdateable = CopyUpdateable();
                return(asyncUpdateable.ExecuteCommand() > 0);
            });

            result.Start();
            return(result);
        }
示例#8
0
        /// <summary>
        /// 功能描述:修改数据
        /// </summary>
        /// <param name="lstColumnValues">列,值</param>
        /// <param name="strWhere">条件</param>
        /// <param name="lstParameters">参数</param>
        /// <returns>是否成功</returns>
        public bool Update(
            Dictionary <string, object> lstColumnValues,
            string strWhere,
            List <SugarParameter> lstParameters)
        {
            IUpdateable <T> up = _db.Updateable <T>(lstColumnValues);

            if (!string.IsNullOrEmpty(strWhere))
            {
                up = up.Where(strWhere, lstParameters);
            }
            return(up.ExecuteCommand() > 0);
        }
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <typeparam name="T">表实体</typeparam>
        /// <param name="entity"></param>
        /// <param name="fileds">需要更新的字段</param>
        /// <param name="where">条件</param>
        /// <returns>受影响行数</returns>
        public int Update <T>(T entity, Expression <Func <T, object> > fileds = null
                              , Expression <Func <T, bool> > where            = null) where T : class, new()
        {
            IUpdateable <T> upd = _db.Updateable(entity);

            if (fileds != null)
            {
                upd.UpdateColumns(fileds);
            }
            if (where != null)
            {
                upd.Where(where);
            }
            return(upd.ExecuteCommand());
        }
示例#10
0
        /// <summary>
        /// 更新 忽略更新某些列 及更新某些列 通过条件判断
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="lstColumns"></param>
        /// <param name="lstIgnoreColumns"></param>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public async Task <bool> Update(TEntity entity, List <string> lstColumns = null, List <string> lstIgnoreColumns = null, string strWhere = "")
        {
            IUpdateable <TEntity> up = await Task.Run(() => db.Updateable(entity));

            if (lstIgnoreColumns != null && lstIgnoreColumns.Count > 0)
            {
                up = await Task.Run(() => up.IgnoreColumns(lstIgnoreColumns.ToArray()));
            }
            if (lstColumns != null && lstColumns.Count > 0)
            {
                up = await Task.Run(() => up.UpdateColumns(lstColumns.ToArray()));
            }
            if (!string.IsNullOrEmpty(strWhere))
            {
                up = await Task.Run(() => up.Where(strWhere));
            }
            return(await Task.Run(() => up.ExecuteCommand()) > 0);
        }
示例#11
0
        public bool Update(T model, List <string> lstColumns = null, List <string> lstIgnoreColumns = null, string strWhere = "")
        {
            IUpdateable <T> up = db.Updateable(model);

            if (lstIgnoreColumns != null && lstIgnoreColumns.Count > 0)
            {
                up = up.IgnoreColumns(lstIgnoreColumns.ToArray());
            }
            if (lstColumns != null && lstColumns.Count > 0)
            {
                up = up.UpdateColumns(lstColumns.ToArray());
            }
            if (!string.IsNullOrEmpty(strWhere))
            {
                up = up.Where(strWhere);
            }
            return(up.ExecuteCommand() > 0);
        }
示例#12
0
        public async Task <bool> Update(TEntity entity, List <string> lstColumns = null, List <string> lstIgnoreColumns = null, string strWhere = "")
        {
            //throw new NotImplementedException();
            IUpdateable <TEntity> up = await Task.Run(() => db.Updateable(entity));

            if (lstIgnoreColumns != null && lstIgnoreColumns.Count > 0)
            {
                up = await Task.Run(() => up.IgnoreColumns(it => lstIgnoreColumns.Contains(it)));
            }
            if (lstColumns != null && lstColumns.Count > 0)
            {
                up = await Task.Run(() => up.UpdateColumns(it => lstColumns.Contains(it)));
            }
            if (!string.IsNullOrEmpty(strWhere))
            {
                up = await Task.Run(() => up.WhereColumns(strWhere));
            }
            return(await Task.Run(() => up.ExecuteCommand()) > 0);
        }
示例#13
0
        /// <summary>
        /// 功能描述:修改指定的列和值
        /// </summary>
        /// <param name="strWhere">条件</param>
        /// <param name="lstParameters">参数</param>
        /// <param name="lstSetValueExpression">列和值列表(如:it => it.Name == (it.Name + 1))</param>
        /// <returns>是否成功</returns>
        public bool Update(
            string strWhere,
            List <SugarParameter> lstParameters,
            params Expression <Func <T, bool> >[] lstSetValueExpression
            )
        {
            IUpdateable <T> up = _db.Updateable <T>();

            if (lstSetValueExpression != null)
            {
                foreach (var item in lstSetValueExpression)
                {
                    up = up.ReSetValue(item);
                }
            }
            if (!string.IsNullOrEmpty(strWhere))
            {
                up = up.Where(strWhere, lstParameters);
            }

            return(up.ExecuteCommand() > 0);
        }
示例#14
0
        /// <summary>
        /// 功能描述:修改数据
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="lstColumns">更新的列,如果为空则不做限制(lstColumns与lstIgnoreColumns互斥)</param>
        /// <param name="lstIgnoreColumns">不更新的列,如果为空则不做限制(lstColumns与lstIgnoreColumns互斥)</param>
        /// <param name="strWhere">条件</param>
        /// <returns>是否成功</returns>
        public bool Update(
            T entity,
            List <string> lstColumns,
            List <string> lstIgnoreColumns,
            string strWhere)
        {
            IUpdateable <T> up = _db.Updateable(entity);

            if (lstIgnoreColumns != null && lstIgnoreColumns.Count > 0)
            {
                up = up.IgnoreColumns(it => lstIgnoreColumns.Contains(it));
            }
            if (lstColumns != null && lstColumns.Count > 0)
            {
                up = up.UpdateColumns(it => lstColumns.Contains(it));
            }
            if (!string.IsNullOrEmpty(strWhere))
            {
                up = up.Where(strWhere);
            }
            return(up.ExecuteCommand() > 0);
        }
示例#15
0
        /// <summary>
        /// 功能描述:修改数据
        /// </summary>
        /// <param name="实体">entity</param>
        /// <param name="lstColumns">更新的列,如果为空则不做限制(lstColumns与lstIgnoreColumns互斥)</param>
        /// <param name="lstIgnoreColumns">不更新的列,如果为空则不做限制(lstColumns与lstIgnoreColumns互斥)</param>
        /// <param name="whereExpression">条件表达式</param>
        /// <returns>是否成功</returns>
        public bool Update(
            T entity,
            List <string> lstColumns,
            List <string> lstIgnoreColumns,
            Expression <Func <T, bool> > whereExpression)
        {
            IUpdateable <T> up = _db.Updateable(entity);

            if (lstIgnoreColumns != null && lstIgnoreColumns.Count > 0)
            {
                up = up.IgnoreColumns(it => lstIgnoreColumns.Contains(it));
            }
            if (lstColumns != null && lstColumns.Count > 0)
            {
                up = up.UpdateColumns(it => lstColumns.Contains(it));
            }
            if (whereExpression != null)
            {
                up = up.Where(whereExpression);
            }
            return(up.ExecuteCommand() > 0);
        }
示例#16
0
        public async Task <bool> Update(
            TEntity entity,
            List <string> lstColumns       = null,
            List <string> lstIgnoreColumns = null,
            string strWhere = ""
            )
        {
            IUpdateable <TEntity> up = await Task.Run(() => _db.Updateable(entity));

            if (lstIgnoreColumns != null && lstIgnoreColumns.Count > 0)
            {
                up = await Task.Run(() => up.IgnoreColumns(it => lstIgnoreColumns.Contains(it)));
            }
            if (lstColumns != null && lstColumns.Count > 0)
            {
                up = await Task.Run(() => up.UpdateColumns(it => lstColumns.Contains(it)));
            }
            if (!string.IsNullOrEmpty(strWhere))
            {
                up = await Task.Run(() => up.Where(strWhere));
            }
            return(await Task.Run(() => up.ExecuteCommand()) > 0);

            //IUpdateable<TEntity> up = _db.Updateable(entity);
            //if (lstIgnoreColumns != null && lstIgnoreColumns.Count > 0)
            //{
            //    up = up.IgnoreColumns(it => lstIgnoreColumns.Contains(it));
            //}
            //if (lstColumns != null && lstColumns.Count > 0)
            //{
            //    up = up.UpdateColumns(it => lstColumns.Contains(it));
            //}
            //if (!string.IsNullOrEmpty(strWhere))
            //{
            //    up = up.Where(strWhere);
            //}
            //return await up.ExecuteCommandHasChangeAsync();
        }
示例#17
0
        /// <summary>
        /// 功能描述:修改数据
        /// </summary>
        /// <param name="entitys">实体列表(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件</param>
        /// <param name="lstColumns">更新的列,如果为空则不做限制(lstColumns与lstIgnoreColumns互斥)</param>
        /// <param name="lstIgnoreColumns">不更新的列,如果为空则不做限制(lstColumns与lstIgnoreColumns互斥)</param>
        /// <param name="strWhere">条件</param>
        /// <param name="lstParameters">条件参数</param>
        /// <returns>受影响行数</returns>
        public int Update(
            T[] entitys,
            List <string> lstColumns,
            List <string> lstIgnoreColumns,
            string strWhere,
            List <SugarParameter> lstParameters)
        {
            IUpdateable <T> up = _db.Updateable(entitys);

            if (lstIgnoreColumns != null && lstIgnoreColumns.Count > 0)
            {
                up = up.IgnoreColumns(it => lstIgnoreColumns.Contains(it));
            }
            if (lstColumns != null && lstColumns.Count > 0)
            {
                up = up.UpdateColumns(it => lstColumns.Contains(it));
            }
            if (!string.IsNullOrEmpty(strWhere))
            {
                up = up.Where(strWhere, lstParameters);
            }
            return(up.ExecuteCommand());
        }
示例#18
0
        public static async Task <bool> Update <TEntity>(
            this SqlSugarClient db,
            TEntity entity,
            List <string> lstColumns       = null,
            List <string> lstIgnoreColumns = null,
            string strWhere = ""
            ) where TEntity : EntityBase, new()
        {
            IUpdateable <TEntity> up = await Task.Run(() => db.Updateable(entity));

            if (lstIgnoreColumns != null && lstIgnoreColumns.Count > 0)
            {
                up = await Task.Run(() => up.IgnoreColumns(it => lstIgnoreColumns.Contains(it)));
            }
            if (lstColumns != null && lstColumns.Count > 0)
            {
                up = await Task.Run(() => up.UpdateColumns(it => lstColumns.Contains(it)));
            }
            if (!string.IsNullOrEmpty(strWhere))
            {
                up = await Task.Run(() => up.Where(strWhere));
            }
            return(await Task.Run(() => up.ExecuteCommand()) > 0);
        }
示例#19
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public int ExecuteCommand()
 {
     return(_updateable.ExecuteCommand());
 }