public IUpdate <T1> Set <TMember>(Expression <Func <T1, TMember> > column, TMember value) { var cols = new List <SelectColumnInfo>(); _commonExpression.ExpressionSelectColumn_MemberAccess(null, cols, SelectTableInfoType.From, column?.Body, true, null); if (cols.Count != 1) { return(this); } var col = cols.First(); object paramVal = null; if (col.Column.Attribute.MapType == typeof(TMember)) { paramVal = value; } else { paramVal = Utils.GetDataReaderValue(col.Column.Attribute.MapType, value); } _set.Append(", ").Append(_commonUtils.QuoteSqlName(col.Column.Attribute.Name)).Append(" = "); if (_noneParameter) { _set.Append(_commonUtils.GetNoneParamaterSqlValue(_params, col.Column.Attribute.MapType, paramVal)); } else { _set.Append(_commonUtils.QuoteWriteParamter(col.Column.Attribute.MapType, $"{_commonUtils.QuoteParamterName("p_")}{_params.Count}")); _commonUtils.AppendParamter(_params, null, col.Column.Attribute.MapType, paramVal); } //foreach (var t in _source) Utils.FillPropertyValue(t, tryf.CsName, value); return(this); }
public IUpdate <T1> Set <TMember>(Expression <Func <T1, TMember> > column, TMember value) { var cols = new List <SelectColumnInfo>(); _commonExpression.ExpressionSelectColumn_MemberAccess(null, cols, SelectTableInfoType.From, column?.Body, true, null); if (cols.Count != 1) { return(this); } var col = cols.First(); _set.Append(", ").Append(_commonUtils.QuoteSqlName(col.Column.Attribute.Name)).Append(" = ").Append(_commonUtils.QuoteWriteParamter(col.Column.CsType, $"{_commonUtils.QuoteParamterName("p_")}{_params.Count}")); _commonUtils.AppendParamter(_params, null, col.Column.CsType, value); //foreach (var t in _source) Utils.FillPropertyValue(t, tryf.CsName, value); return(this); }
public string ToSql() { if (_source == null || _source.Any() == false) { return(null); } var sb = new StringBuilder(); sb.Append("INSERT INTO ").Append(_commonUtils.QuoteSqlName(_table.DbName)).Append("("); var colidx = 0; foreach (var col in _table.Columns.Values) { if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name) == false) { if (colidx > 0) { sb.Append(", "); } sb.Append(_commonUtils.QuoteSqlName(col.Attribute.Name)); ++colidx; } } sb.Append(") VALUES"); _params = new DbParameter[colidx * _source.Count]; var didx = 0; foreach (var d in _source) { if (didx > 0) { sb.Append(", "); } sb.Append("("); var colidx2 = 0; foreach (var col in _table.Columns.Values) { if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name) == false) { if (colidx2 > 0) { sb.Append(", "); } sb.Append(_commonUtils.QuoteWriteParamter(col.CsType, $"{_commonUtils.QuoteParamterName(col.CsName)}{didx}")); _params[didx * colidx + colidx2] = _commonUtils.AppendParamter(null, $"{col.CsName}{didx}", col.CsType, _table.Properties.TryGetValue(col.CsName, out var tryp) ? tryp.GetValue(d) : null); ++colidx2; } } sb.Append(")"); ++didx; } return(sb.ToString()); }
protected void SetPriv(ColumnInfo col, object value) { object paramVal = null; if (col.Attribute.MapType == col.CsType) { paramVal = value; } else { paramVal = Utils.GetDataReaderValue(col.Attribute.MapType, value); } _set.Append(", ").Append(_commonUtils.QuoteSqlName(col.Attribute.Name)).Append(" = "); if (_noneParameter) { _set.Append(_commonUtils.GetNoneParamaterSqlValue(_params, col.Attribute.MapType, paramVal)); } else { _set.Append(_commonUtils.QuoteWriteParamter(col.Attribute.MapType, $"{_commonUtils.QuoteParamterName("p_")}{_params.Count}")); _commonUtils.AppendParamter(_params, null, col, col.Attribute.MapType, paramVal); } }
protected void SetPriv(ColumnInfo col, object value) { object val = null; if (col.Attribute.MapType == col.CsType) { val = value; } else { val = Utils.GetDataReaderValue(col.Attribute.MapType, value); } _set.Append(", ").Append(_commonUtils.QuoteSqlName(col.Attribute.Name)).Append(" = "); var colsql = _noneParameter ? _commonUtils.GetNoneParamaterSqlValue(_params, "u", col, col.Attribute.MapType, val) : _commonUtils.QuoteWriteParamterAdapter(col.Attribute.MapType, $"{_commonUtils.QuoteParamterName("p_")}{_params.Count}"); _set.Append(_commonUtils.RewriteColumn(col, colsql)); if (_noneParameter == false) { _commonUtils.AppendParamter(_params, null, col, col.Attribute.MapType, val); } }
public string ToSqlValuesOrSelectUnionAll(bool isValues = true) { if (_source == null || _source.Any() == false) { return(null); } var sb = new StringBuilder(); sb.Append("INSERT INTO ").Append(_commonUtils.QuoteSqlName(TableRuleInvoke())).Append("("); var colidx = 0; foreach (var col in _table.Columns.Values) { if (col.Attribute.IsIdentity && _insertIdentity == false) { continue; } if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name)) { continue; } if (colidx > 0) { sb.Append(", "); } sb.Append(_commonUtils.QuoteSqlName(col.Attribute.Name)); ++colidx; } sb.Append(") "); if (isValues) { sb.Append(isValues ? "VALUES" : "SELECT "); } _params = _noneParameter ? new DbParameter[0] : new DbParameter[colidx * _source.Count]; var specialParams = new List <DbParameter>(); var didx = 0; foreach (var d in _source) { if (didx > 0) { sb.Append(isValues ? ", " : " \r\nUNION ALL\r\n "); } sb.Append(isValues ? "(" : "SELECT "); var colidx2 = 0; foreach (var col in _table.Columns.Values) { if (col.Attribute.IsIdentity && _insertIdentity == false) { continue; } if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name)) { continue; } if (colidx2 > 0) { sb.Append(", "); } if (string.IsNullOrEmpty(col.DbInsertValue) == false) { sb.Append(col.DbInsertValue); } else { object val = col.GetMapValue(d); if (_noneParameter) { sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, col.Attribute.MapType, val)); } else { sb.Append(_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"{col.CsName}_{didx}"))); _params[didx * colidx + colidx2] = _commonUtils.AppendParamter(null, $"{col.CsName}_{didx}", col, col.Attribute.MapType, val); } } ++colidx2; } if (isValues) { sb.Append(")"); } ++didx; } if (_noneParameter && specialParams.Any()) { _params = specialParams.ToArray(); } return(sb.ToString()); }
public virtual string ToSql() { if (_source == null || _source.Any() == false) { return(null); } var sb = new StringBuilder(); sb.Append("INSERT INTO ").Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(_table.DbName) ?? _table.DbName)).Append("("); var colidx = 0; foreach (var col in _table.Columns.Values) { if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name) == false) { if (colidx > 0) { sb.Append(", "); } sb.Append(_commonUtils.QuoteSqlName(col.Attribute.Name)); ++colidx; } } sb.Append(") VALUES"); _params = _noneParameter ? new DbParameter[0] : new DbParameter[colidx * _source.Count]; var specialParams = new List <DbParameter>(); var didx = 0; foreach (var d in _source) { if (didx > 0) { sb.Append(", "); } sb.Append("("); var colidx2 = 0; foreach (var col in _table.Columns.Values) { if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name) == false) { if (colidx2 > 0) { sb.Append(", "); } object val = null; if (_table.Properties.TryGetValue(col.CsName, out var tryp)) { val = tryp.GetValue(d); if (col.Attribute.IsPrimary && (col.CsType == typeof(Guid) || col.CsType == typeof(Guid?)) && (val == null || (Guid)val == Guid.Empty)) { tryp.SetValue(d, val = FreeUtil.NewMongodbId()); } } if (_noneParameter) { sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, col.CsType, val)); } else { sb.Append(_commonUtils.QuoteWriteParamter(col.CsType, _commonUtils.QuoteParamterName($"{col.CsName}_{didx}"))); _params[didx * colidx + colidx2] = _commonUtils.AppendParamter(null, $"{col.CsName}_{didx}", col.CsType, val); } ++colidx2; } } sb.Append(")"); ++didx; } if (_noneParameter && specialParams.Any()) { _params = specialParams.ToArray(); } return(sb.ToString()); }
public string ToSqlValuesOrSelectUnionAllExtension102(bool isValues, Action <object, int, StringBuilder> onrowPre, Action <object, int, StringBuilder> onrow) { if (_source == null || _source.Any() == false) { return(null); } var sb = new StringBuilder(); sb.Append("INSERT INTO ").Append(_commonUtils.QuoteSqlName(TableRuleInvoke())).Append('('); var colidx = 0; foreach (var col in _table.Columns.Values) { if (col.Attribute.IsIdentity && _insertIdentity == false && string.IsNullOrEmpty(col.DbInsertValue)) { continue; } if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name)) { continue; } if (colidx > 0) { sb.Append(", "); } sb.Append(_commonUtils.QuoteSqlName(col.Attribute.Name)); ++colidx; } sb.Append(") "); if (isValues) { sb.Append("VALUES"); } _params = _noneParameter ? new DbParameter[0] : new DbParameter[colidx * _source.Count]; var specialParams = new List <DbParameter>(); var didx = 0; foreach (var d in _source) { if (didx > 0) { sb.Append(isValues ? ", " : " \r\nUNION ALL\r\n "); } sb.Append(isValues ? "(" : "SELECT "); onrowPre?.Invoke(d, didx, sb); var colidx2 = 0; foreach (var col in _table.Columns.Values) { if (col.Attribute.IsIdentity && _insertIdentity == false && string.IsNullOrEmpty(col.DbInsertValue)) { continue; } if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name)) { continue; } if (colidx2 > 0) { sb.Append(", "); } if (string.IsNullOrEmpty(col.DbInsertValue) == false) { sb.Append(col.DbInsertValue); } else { object val = col.GetDbValue(d); if (val == null && col.Attribute.IsNullable == false) { val = col.CsType == typeof(string) ? "" : Utils.GetDataReaderValue(col.CsType.NullableTypeOrThis(), null); //#384 } if (_noneParameter) { sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, _noneParameterFlag, col, col.Attribute.MapType, val)); } else { sb.Append(_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"{col.CsName}_{didx}"))); _params[didx * colidx + colidx2] = _commonUtils.AppendParamter(null, $"{col.CsName}_{didx}", col, col.Attribute.MapType, val); } } ++colidx2; } if (isValues) { sb.Append(')'); } onrow?.Invoke(d, didx, sb); ++didx; } if (_noneParameter && specialParams.Any()) { _params = specialParams.ToArray(); } return(sb.ToString()); }
public virtual string ToSql() { if (_source == null || _source.Any() == false) { return(null); } var sb = new StringBuilder(); sb.Append("INSERT INTO ").Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(_table.DbName) ?? _table.DbName)).Append("("); var colidx = 0; foreach (var col in _table.Columns.Values) { if (_ignore.ContainsKey(col.Attribute.Name)) { continue; } if (col.Attribute.IsIdentity && _insertIdentity == false) { continue; } if (colidx > 0) { sb.Append(", "); } sb.Append(_commonUtils.QuoteSqlName(col.Attribute.Name)); ++colidx; } sb.Append(") VALUES"); _params = _noneParameter ? new DbParameter[0] : new DbParameter[colidx * _source.Count]; var specialParams = new List <DbParameter>(); var didx = 0; foreach (var d in _source) { if (didx > 0) { sb.Append(", "); } sb.Append("("); var colidx2 = 0; foreach (var col in _table.Columns.Values) { if (_ignore.ContainsKey(col.Attribute.Name)) { continue; } if (col.Attribute.IsIdentity && _insertIdentity == false) { continue; } if (colidx2 > 0) { sb.Append(", "); } object val = col.GetMapValue(d); if (_noneParameter) { sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, col.Attribute.MapType, val)); } else { sb.Append(_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"{col.CsName}_{didx}"))); _params[didx * colidx + colidx2] = _commonUtils.AppendParamter(null, $"{col.CsName}_{didx}", col.Attribute.MapType, val); } ++colidx2; } sb.Append(")"); ++didx; } if (_noneParameter && specialParams.Any()) { _params = specialParams.ToArray(); } return(sb.ToString()); }