当前位置: 首页>>代码示例>>C#>>正文


C# SelectQuery.Clone方法代码示例

本文整理汇总了C#中SelectQuery.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# SelectQuery.Clone方法的具体用法?C# SelectQuery.Clone怎么用?C# SelectQuery.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SelectQuery的用法示例。


在下文中一共展示了SelectQuery.Clone方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RenderPage

		/// <summary>
		/// Renders a SELECT statement which a result-set page
		/// </summary>
		/// <param name="pageIndex">The zero based index of the page to be returned</param>
		/// <param name="pageSize">The size of a page</param>
		/// <param name="totalRowCount">Total number of rows the query would yeild if not paged</param>
		/// <param name="query">Query definition to apply paging on</param>
		/// <returns>Generated SQL statement</returns>
		/// <remarks>
		/// To generate pagination SQL you must supply <paramref name="totalRowCount"/>.
		/// To aquire the total number of rows use the <see cref="RenderRowCount"/> method.
		/// </remarks>
		public virtual string RenderPage(int pageIndex, int pageSize, int totalRowCount, SelectQuery query)
		{
			if (query.OrderByTerms.Count == 0)
			{
				throw new InvalidQueryException("OrderBy must be specified for paging to work.");
			}

			int currentPageSize = pageSize;
			if (pageSize*(pageIndex + 1) > totalRowCount)
			{
				currentPageSize = totalRowCount - pageSize*pageIndex;
			}
			if (currentPageSize < 0)
			{
				currentPageSize = 0;
			}

			SelectQuery baseQuery = query.Clone();

			baseQuery.Top = (pageIndex + 1)*pageSize;
			//baseQuery.Columns.Add(new SelectColumn("*"));
			foreach (OrderByTerm term in baseQuery.OrderByTerms)
			{
				baseQuery.Columns.Add(
					new SelectColumn(term.Field, term.Table, FormatSortFieldName(term.Field),
					                 SqlAggregationFunction.None));
			}

			string baseSql = RenderSelect(baseQuery);

			SelectQuery reverseQuery = new SelectQuery();
			reverseQuery.Columns.Add(new SelectColumn("*"));
			reverseQuery.Top = currentPageSize;
			reverseQuery.FromClause.BaseTable = FromTerm.SubQuery(baseSql, "r");
			ApplyOrderBy(baseQuery.OrderByTerms, reverseQuery, false, reverseQuery.FromClause.BaseTable);
			string reverseSql = RenderSelect(reverseQuery);

			SelectQuery forwardQuery = new SelectQuery();
			foreach (SelectColumn originalCol in query.Columns)
			{
				FromTerm forwardTable = FromTerm.TermRef("f");
				SqlExpression expr = null;
				if (originalCol.ColumnAlias != null)
				{
					expr = SqlExpression.Field(originalCol.ColumnAlias, forwardTable);
				}
				else if (originalCol.Expression.Type == SqlExpressionType.Field ||
				         originalCol.Expression.Type == SqlExpressionType.Constant)
				{
					expr = SqlExpression.Field((string) originalCol.Expression.Value, forwardTable);
				}

				if (expr != null)
				{
					forwardQuery.Columns.Add(new SelectColumn(expr, originalCol.ColumnAlias));
				}
			}

			forwardQuery.FromClause.BaseTable = FromTerm.SubQuery(reverseSql, "f");
			ApplyOrderBy(baseQuery.OrderByTerms, forwardQuery, true, forwardQuery.FromClause.BaseTable);

			return RenderSelect(forwardQuery);
		}
开发者ID:TargetProcess,项目名称:Tp.HelpDesk,代码行数:75,代码来源:SqlOmRenderer.cs

示例2: RenderRowCount

		/// <summary>
		/// Renders a row count SELECT statement. 
		/// </summary>
		/// <param name="query">Query definition to count rows for</param>
		/// <returns>Generated SQL statement</returns>
		/// <remarks>
		/// Renders a SQL statement which returns a result set with one row and one cell which contains the number of rows <paramref name="query"/> can generate. 
		/// The generated statement will work nicely with <see cref="System.Data.IDbCommand.ExecuteScalar"/> method.
		/// </remarks>
		public override string RenderRowCount(SelectQuery query)
		{
			SelectQuery queryAddition = query.Clone();
			queryAddition.Columns.Clear();

			SelectColumn col = new SelectColumn("*", null, "", SqlAggregationFunction.Count);
			queryAddition.Columns.Add(col);

			queryAddition.OrderByTerms.Clear();

			return RenderSelect(queryAddition);
		}
开发者ID:TargetProcess,项目名称:Tp.HelpDesk,代码行数:21,代码来源:HqlRenderer.cs


注:本文中的SelectQuery.Clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。