本文整理匯總了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);
}