Example #1
0
        public int Update(string tableName, DbFields values, string whereCondition, DbParameters parameters = null)
        {
            if (parameters == null)
            {
                parameters = new DbParameters();
            }

            if (!string.IsNullOrWhiteSpace(whereCondition) && !whereCondition.Trim().ToUpper().StartsWith("WHERE"))
            {
                whereCondition = $"WHERE {whereCondition}";
            }

            var queryParameters = new DbParameters(
                values.ToDictionary(x => x.Key, x => x.Value));

            queryParameters.Concat(
                parameters.ToDictionary(x => x.Key, x => x.Value));

            return(this.ExecuteNonQuery(
                       $"UPDATE [{tableName}] SET {string.Join(", ", values.Select(x => $"[{x.Key}]=@{x.Key}"))} {whereCondition}",
                       queryParameters));
        }