本文整理汇总了C#中Columns.Select方法的典型用法代码示例。如果您正苦于以下问题:C# Columns.Select方法的具体用法?C# Columns.Select怎么用?C# Columns.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Columns
的用法示例。
在下文中一共展示了Columns.Select方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigurePagedListCommand
/// <summary>
/// 根据查询条件分页返回数据。
/// </summary>
/// <param name="command">SQL命令执行对象</param>
/// <param name="tableName">表名称</param>
/// <param name="allColumns">所有列信息</param>
/// <param name="pageIndex">当前页数</param>
/// <param name="pageSize">每页显示记录数</param>
/// <param name="totalRecords">总记录数</param>
/// <param name="criteria"></param>
/// <param name="columns">数据库信息返回列表</param>
/// <returns>命令执行对象</returns>
protected override void ConfigurePagedListCommand(DbCommand command, string tableName, Columns allColumns, int pageIndex, int pageSize, out int totalRecords, Criteria criteria = null, string[] columns = null)
{
int index;
var returnColumns = columns ?? allColumns.Select(c => c.Name);
var commandTextBuilder = new StringBuilder();
var totalRecordCommandTextBuilder = new StringBuilder();
var conditionTextBuilder = new StringBuilder();
commandTextBuilder.Append("SELECT ");
totalRecordCommandTextBuilder.AppendFormat("SELECT COUNT(*) FROM {0} ", this.GetSafeTableName(tableName));
commandTextBuilder.Append("ROW_NUMBER() OVER(ORDER BY ");
var primaryKeys = allColumns.Where(c => c.IsPrimaryKey);
// 添加排序条件。
if (criteria != null && !criteria.Orders.IsEmpty())
{
index = 1;
foreach (var order in criteria.Orders)
{
commandTextBuilder.AppendFormat((criteria.Orders.Count == index++) ? "\"{0}\" {1}" : "\"{0}\" {1},",
allColumns[order.PropertyName].Name, order.OrderBy);
}
}
else if (!primaryKeys.IsEmpty())
{
index = 1;
foreach (var item in primaryKeys)
{
commandTextBuilder.AppendFormat(primaryKeys.Count() == index ? "\"{0}\"" : "\"{0}\",", item.Name);
index++;
}
}
else
{
commandTextBuilder.AppendFormat("\"{0}\"", allColumns.FirstOrDefault().Name);
}
commandTextBuilder.Append(") AS \"RowIndex\"");
foreach (var item in returnColumns)
{
commandTextBuilder.AppendFormat(",\"{0}\"", allColumns[item].Name);
}
commandTextBuilder.AppendFormat(" FROM {0} ", this.GetSafeTableName(tableName));
var effectiveConditions = criteria?.EffectiveConditions;
// 添加查询条件。
if (!effectiveConditions.IsEmpty())
{
index = 1;
foreach (var item in effectiveConditions)
{
var fragment = this.CreateFragment(allColumns[item.PropertyName].Name, item.Op);
conditionTextBuilder.Append(fragment.Item1);
if (index < effectiveConditions.Count)
{
conditionTextBuilder.AppendFormat(" {0} ", effectiveConditions[index].JoinType);
}
if ((int)item.Op <= 5)
{
command.AddParameter($":{fragment.Item2}", item.Value);
}
index++;
}
}
if (!string.IsNullOrWhiteSpace(conditionTextBuilder.ToString()))
{
commandTextBuilder.Append("WHERE ");
commandTextBuilder.Append(conditionTextBuilder);
totalRecordCommandTextBuilder.Append("WHERE ");
totalRecordCommandTextBuilder.Append(conditionTextBuilder);
}
commandTextBuilder.Append(" Order By \"RowIndex\" ASC ");
commandTextBuilder.AppendFormat("OFFSET (:pageIndex-1)*:pageSize LIMIT :pageSize");
command.CommandType = CommandType.Text;
//.........这里部分代码省略.........