Пример #1
0
        int IEntityOperator.UpdateValues(SchemaModel.Column keyColumn, SchemaModel.Table table, Dictionary <string, object> values)
        {
            var keyValue = values.Get(keyColumn.Name);

            if (keyValue == null)
            {
                throw new InvalidOperationException("字典未传入主键");
            }
            var updateSql     = "UPDATE {0} SET {1} WHERE {2}";
            var tableName     = _sqlBuilder.GetTableName(table);
            var sqlParameters = new Dictionary <string, object>();
            var setts         = new List <string>();
            var alias         = string.Empty;

            foreach (var key in values.Keys)
            {
                if (key == keyColumn.Name)
                {
                    continue;
                }
                alias = ParserUtils.GenerateAlias(key);
                var set = string.Format("[{0}] = @{1}", key, alias);
                sqlParameters.Add(alias, values.Get(key));
                setts.Add(set);
            }
            alias = ParserUtils.GenerateAlias(keyColumn.Name);
            var condition = string.Format("[{0}] = @{1}", keyColumn.Name, alias);

            sqlParameters.Add(alias, keyValue);
            updateSql = string.Format(updateSql, tableName, string.Join(",", setts), condition);
            return(_sqlExecutor.ExecuteNonQuery(updateSql, sqlParameters));
        }
Пример #2
0
        int IEntityOperator.Delete(SchemaModel.Column keyColumn, SchemaModel.Table table, params int[] ids)
        {
            if (ids.Length <= 0)
            {
                return(0);
            }
            var deleteSql = "DELETE FROM {0} WHERE [{1}] IN ({2})";
            var tableName = _sqlBuilder.GetTableName(table);

            deleteSql = string.Format(deleteSql, tableName, keyColumn.Name, string.Join(",", ids));
            return(_sqlExecutor.ExecuteNonQuery(deleteSql, new Dictionary <string, object>()));
        }