private void PrepareUpdateSql() { SqlText.AppendFormat("Update {0} set ", TableName); Separator = null; for (var index = 0; index < SqlColumns.Length; index++) { var columnInfo = SqlColumns[index]; if (columnInfo.IsInPrimaryKey || columnInfo.IsDatabaseGenerated) { continue; } AddSeparator(", "); SqlText.Append(Encode(columnInfo.ColumnName) + "=@p" + ParameterValues.Count); ParameterValues.Add(columnInfo.ValueReader.ReadPropertyValue(Entity)); } SqlText.Append(" where "); Separator = null; foreach (var i in SqlColumns) { if (!i.IsInPrimaryKey) { continue; } AddSeparator(" AND "); SqlText.Append(Encode(i.ColumnName) + "=@p" + ParameterValues.Count); ParameterValues.Add(i.ValueReader.ReadPropertyValue(Entity)); } }
private IReadOnlyList <ColumnInfo> PrepareUpdateSql(bool skipSelect) { var whereSql = PrepareWhereSql(); SqlText.AppendFormat("Update {0} set ", TableName); Separator = null; for (var index = 0; index < SqlColumns.Count; index++) { var columnInfo = SqlColumns[index]; if (columnInfo.IsInPrimaryKey || columnInfo.IsDatabaseGenerated) { continue; } AddSeparator(", "); SqlText.Append(Encode(columnInfo.ColumnName) + "=@p" + ParameterValues.Count); ParameterValues.Add(columnInfo.ValueReader.ReadPropertyValue(Entity)); } SqlText.Append(whereSql); if (skipSelect) { return(new ColumnInfo[0]); } var returned = SqlColumns.Where(a => a.IsDatabaseGenerated && !a.IsInPrimaryKey).ToList(); if (!returned.Any()) { return(returned); } SqlText.Append("; select " + string.Join(",", returned.Select(q => Encode(q.ColumnName)))); SqlText.Append(" from " + TableName); SqlText.Append(whereSql); return(returned); }
private void PrepareUpdateSql(IReadOnlyDictionary <string, object> keys) { SqlText.AppendFormat("delete from {0} ", TableName); SqlText.Append(" where "); Separator = null; foreach (var i in keys) { AddSeparator(" AND "); SqlText.Append(Encode(i.Key) + "=@p" + ParameterValues.Count); ParameterValues.Add(i.Value); } }
private void PrepareInsertSql() { SqlText.AppendFormat("INSERT INTO {0} (", TableName); Separator = null; for (var index = 0; index < SqlColumns.Count; index++) { var col = SqlColumns[index]; if (col.IsIdentity || col.IsDatabaseGenerated) { continue; } AddSeparator(", "); SqlText.Append(Encode(col.ColumnName)); AddPropertyValue(index); } SqlText.Append(") values ("); Separator = null; for (var parameterIdx = 0; parameterIdx < ParameterValues.Count; parameterIdx++) { AddSeparator(", "); SqlText.Append($"@p{parameterIdx}"); } SqlText.AppendLine(");"); }