本文整理汇总了C#中Columns.Any方法的典型用法代码示例。如果您正苦于以下问题:C# Columns.Any方法的具体用法?C# Columns.Any怎么用?C# Columns.Any使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Columns
的用法示例。
在下文中一共展示了Columns.Any方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureCreateCommand
/// <summary>
/// 添加数据。
/// </summary>
/// <param name="command">SQL命令执行对象</param>
/// <param name="tableName">表名称</param>
/// <param name="allColumns">所有列信息</param>
/// <returns>命令执行对象</returns>
protected override void ConfigureCreateCommand(DbCommand command, string tableName, Columns allColumns)
{
var index = 1;
var insertColumns = allColumns.Where(c => !c.IsIdentity);
var commandTextBuilder = new StringBuilder();
commandTextBuilder.AppendFormat("INSERT INTO {0} (", this.GetSafeTableName(tableName));
foreach (var column in insertColumns)
{
commandTextBuilder.AppendFormat(index++ == insertColumns.Count() ? "\"{0}\"" : "\"{0}\",", column.Name);
}
commandTextBuilder.AppendFormat(") VALUES (");
index = 1;
foreach (var item in insertColumns)
{
var format = index++ == insertColumns.Count() ? ":{0}" : ":{0}, ";
commandTextBuilder.AppendFormat(format, item.Name);
command.AddParameter($":{item.Name}", item.Value, this._dbTypeResolve.GetDbType(item.DataType));
}
commandTextBuilder.Append(")");
if (allColumns.Any(c => c.IsIdentity))
{
var identity = allColumns.First(i => i.IsIdentity);
commandTextBuilder.AppendFormat(";SELECT currval(pg_get_serial_sequence('{0}', '{1}'));", this.GetSafeTableName(tableName), identity.Name);
}
command.CommandType = CommandType.Text;
command.CommandText = commandTextBuilder.ToString();
this.RecordCommandInfo("添加记录", command);
}
示例2: ConfigureCreateCommand
/// <summary>
/// 添加数据。
/// </summary>
/// <param name="command">SQL命令执行对象</param>
/// <param name="tableName">表名称</param>
/// <param name="allColumns">所有列信息</param>
/// <returns>命令执行对象</returns>
protected override void ConfigureCreateCommand(DbCommand command, string tableName, Columns allColumns)
{
var index = 1;
var insertColumns = allColumns.Where(c => !c.IsIdentity);
var commandTextBuilder = new StringBuilder();
commandTextBuilder.AppendFormat("INSERT INTO {0} (", this.GetSafeTableName(tableName));
foreach (var column in insertColumns)
{
commandTextBuilder.AppendFormat(index++ == insertColumns.Count() ? "[{0}]" : "[{0}],", column.Name);
}
commandTextBuilder.AppendFormat(") VALUES (");
index = 1;
foreach (var item in insertColumns)
{
var format = index++ == insertColumns.Count() ? "@{0}" : "@{0}, ";
commandTextBuilder.AppendFormat(format, item.Name);
command.AddParameter($"@{item.Name}", item.Value);
}
commandTextBuilder.Append(")");
if (allColumns.Any(c => c.IsIdentity))
{
commandTextBuilder.Append(";SELECT @@IDENTITY;");
}
command.CommandType = CommandType.Text;
command.CommandText = commandTextBuilder.ToString();
this.RecordCommandInfo("添加记录", command);
}