public string Update(IClassMapper classMap, IPredicate predicate, IDictionary <string, object> parameters) { Guard.ArgumentNull(predicate, nameof(predicate)); Guard.ArgumentNull(parameters, nameof(parameters)); var context = new SqlGenerationContext(Configuration.Dialect, classMap); var setSql = _updateCache.GetOrAdd(classMap.EntityType.TypeHandle, x => { var columns = classMap.GetMutableColumns(); if (!columns.Any()) { throw new ArgumentException("No columns were mapped."); } return(columns.Select( p => $"{GetColumnName(classMap, p, false)} = {Configuration.Dialect.ParameterPrefix}{p.Name}") .AppendStrings()); }); return($"UPDATE {GetTableName(classMap)} SET {setSql} WHERE {predicate.GetSql(context, parameters)}"); }
private string GetUpdateSection(IClassMapper classMap) { var columns = classMap.GetMutableColumns(); var updateSql = columns.Select( p => $"{GetColumnName(classMap, p, false)} = {Configuration.Dialect.ParameterPrefix}{p.Name}"); return(string.Join(", ", updateSql)); }
private string GetUpdateSection(IClassMapper classMap) { var columns = classMap.GetMutableColumns(); var updateSql = columns.Select( p => $"{GetColumnName(p.ColumnName, null)} = {ParameterPrefix}{p.Name}"); return(string.Join(", ", updateSql)); }
public ActionParams Update(IClassMapper classMap, object entity) { var predicate = classMap.GetKeyPredicate(entity); var parameters = new Dictionary <string, object>(); var sql = SqlGenerator.Update(classMap, predicate, parameters); var dynamicParameters = new DynamicParameters(); var columns = classMap.GetMutableColumns(); foreach (var property in ReflectionHelper.GetObjectValues(entity) .Where(property => columns.Any(c => c.Name == property.Key))) { dynamicParameters.Add(property.Key, property.Value); } foreach (var parameter in parameters) { dynamicParameters.Add(parameter.Key, parameter.Value); } return(ActionParams.New(sql, dynamicParameters)); }
public MultiActionParams InsertBatch(IClassMapper classMap, IEnumerable <object> entities) { var parameters = new List <DynamicParameters>(); var columns = classMap.GetMutableColumns(); var guids = new IPropertyMap[0]; if (Configuration.AutoPopulateKeyGuidValue) { guids = columns.Where(x => x.PropertyInfo.PropertyType == typeof(Guid)).ToArray(); } foreach (var e in entities) { foreach (var guid in guids) { if ((Guid)guid.Getter(e) == Guid.Empty) { var value = Configuration.GuidCreator.GetGuid(); guid.Setter(e, value); } } var dynamicParameters = new DynamicParameters(); foreach (var column in columns) { dynamicParameters.Add(column.Name, column.Getter(e)); } parameters.Add(dynamicParameters); } var sql = SqlGenerator.Insert(classMap); return(MultiActionParams.New(sql, parameters)); }