本文整理汇总了C#中Columns.Count方法的典型用法代码示例。如果您正苦于以下问题:C# Columns.Count方法的具体用法?C# Columns.Count怎么用?C# Columns.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Columns
的用法示例。
在下文中一共展示了Columns.Count方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureUpdateCommand
/// <summary>
/// 更新数据。
/// </summary>
/// <param name="command">SQL命令执行对象</param>
/// <param name="tableName">表名称</param>
/// <param name="allColumns">所有列信息</param>
/// <param name="columns">更新列集合</param>
/// <param name="criteria"></param>
/// <returns>命令执行对象</returns>
protected override void ConfigureUpdateCommand(DbCommand command, string tableName, Columns allColumns, Columns columns, Criteria criteria = null)
{
var index = 1;
var commandTextBuilder = new StringBuilder();
commandTextBuilder.AppendFormat("UPDATE {0} SET ", this.GetSafeTableName(tableName));
foreach (var item in columns)
{
var format = index++ == columns.Count() ? "\"{0}\"=:{0}" : "\"{0}\"=:{0},";
commandTextBuilder.AppendFormat(format, columns[item.Name].Name);
command.AddParameter($":{columns[item.Name].Name}", item.Value, this._dbTypeResolve.GetDbType(columns[item.Name].DataType));
}
var effectiveConditions = criteria?.EffectiveConditions;
if (effectiveConditions.IsEmpty())
{
var primaryKeys = columns.Where(c => c.IsPrimaryKey).Select(c => c.Name);
if (primaryKeys.Any())
{
commandTextBuilder.Append(" WHERE ");
index = 1;
foreach (var item in primaryKeys)
{
commandTextBuilder.AppendFormat(primaryKeys.Count() == index++ ? " \"{0}\"=:{0}" : "\"{0}\"=:{0} AND ", columns[item].Name);
command.AddParameter($":{columns[item].Name}", columns[item].Value, this._dbTypeResolve.GetDbType(columns[item].DataType));
}
}
}
else
{
index = 1;
commandTextBuilder.Append(" WHERE ");
foreach (var item in effectiveConditions)
{
var columnName = allColumns[item.PropertyName].Name;
var fragment = this.CreateFragment(columnName, item.Op);
commandTextBuilder.Append(fragment.Item1);
if (index < effectiveConditions.Count)
{
commandTextBuilder.AppendFormat(" {0} ", effectiveConditions[index].JoinType);
}
if ((int)item.Op <= 5)
{
command.AddParameter($":{fragment.Item2}", item.Value, this._dbTypeResolve.GetDbType(columns[item.PropertyName].DataType));
}
index++;
}
}
command.CommandType = CommandType.Text;
command.CommandText = commandTextBuilder.ToString();
this.RecordCommandInfo("更新记录", command);
}