Ejemplo n.º 1
0
        /// <summary>
        /// 传参数按主键更新数据(参数中必须包含全部主键列)
        /// </summary>
        /// <param name="parameters">全部参数</param>
        /// <param name="changecolumns">需要更新的参数</param>
        /// <param name="offsetParameters">需要偏移更新的参数(update xxx set a=a+@a...)</param>
        /// <returns></returns>
        public int Update(HashObject parameters, string[] changecolumns = null, string[] offsetParameters = null)
        {
            this.CheckForPrimary(parameters);//判断参数中是否包含主键列,如果不包含,抛出异常

            string     hostColName     = DALConfig.GetHostColName(this._dbName);
            HashObject whereParameters = new HashObject();

            whereParameters.Add(this._primaryColumn, parameters[this._primaryColumn]);
            whereParameters.Add(hostColName, parameters[hostColName]);

            HashObject setParameters = new HashObject();

            if (changecolumns != null)
            {
                foreach (string column in changecolumns)
                {
                    setParameters[column] = parameters[column];
                }
            }
            else
            {
                setParameters = parameters.Copy();
                setParameters.Remove(this._primaryColumn); //移除主键列
                setParameters.Remove(hostColName);         //移除分区列
            }

            return(UpdateByWhere(setParameters, whereParameters, offsetParameters));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据主键删除(单主键)
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public bool DeleteByPrimary(HashObject parameters)
        {
            HashObject delparameters = parameters.Copy(new string[] { "profileid" });

            delparameters["#" + this._primaryColumn] = parameters[this._primaryColumn];
            bool result = this.Delete(delparameters);

            return(result);
        }