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


C# SelectExpression.SetSkip方法代码示例

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


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

示例1: VisitSelect

		protected override Expression VisitSelect(SelectExpression select)
		{
			select = (SelectExpression)base.VisitSelect(select);
			if (select.Skip != null)
			{
				SelectExpression newSelect = select.SetSkip(null).SetTake(null);
				bool canAddColumn = !select.IsDistinct && (select.GroupBy == null || select.GroupBy.Count == 0);
				if (!canAddColumn)
				{
					newSelect = newSelect.AddRedundantSelect(new TableAlias());
				}

				var colType = DbTypeSystem.GetColumnType(typeof(int));
				newSelect = newSelect.AddColumn(new ColumnDeclaration(columnName, new RowNumberExpression(select.OrderBy), colType));

				// add layer for WHERE clause that references new rownum column
				newSelect = newSelect.AddRedundantSelect(new TableAlias());
				newSelect = newSelect.RemoveColumn(newSelect.Columns.Single(c => c.Name == columnName));

				var newAlias = ((SelectExpression)newSelect.From).Alias;
				ColumnExpression rnCol = new ColumnExpression(typeof(int), colType, newAlias, columnName);
				Expression where;

				if (select.Take != null)
				{
					where = new BetweenExpression(
						rnCol, Expression.Add(select.Skip, Expression.Constant(1)), Expression.Add(select.Skip, select.Take));
				}
				else
				{
					where = rnCol.GreaterThan(select.Skip);
				}

				if (newSelect.Where != null)
				{
					where = newSelect.Where.And(where);
				}

				newSelect = newSelect.SetWhere(where);

				select = newSelect;
			}

			return select;
		}
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm.Linq,代码行数:45,代码来源:SkipToRowNumberRewriter.cs

示例2: VisitSelect

        protected override Expression VisitSelect(SelectExpression select)
        {
            select = (SelectExpression)base.VisitSelect(select);

            if (select.Skip != null) {
                var newSelect = select.SetSkip(null).SetTake(null).AddRedundantSelect(_language, new TableAlias());

                _hasRowNumberExpression = true;

                var colType = _language.TypeSystem.GetColumnType(typeof(int));

                newSelect = newSelect.AddColumn(new ColumnDeclaration("rownum", new RowNumberExpression(select.OrderBy), colType));

                // add layer for WHERE clause that references new rownum column
                newSelect = newSelect.AddRedundantSelect(_language, new TableAlias());
                newSelect = newSelect.RemoveColumn(newSelect.Columns.Single(c => c.Name == "rownum"));

                var newAlias = ((SelectExpression)newSelect.From).Alias;
                var rowNumberColumn = new ColumnExpression(typeof(int), colType, newAlias, "rownum");

                Expression where;

                if (select.Take != null) {
                    where = new BetweenExpression(rowNumberColumn, Expression.Add(select.Skip, Expression.Constant(1)), Expression.Add(select.Skip, select.Take));
                }
                else {
                    where = rowNumberColumn.GreaterThan(select.Skip);
                }

                if (newSelect.Where != null) {
                    where = newSelect.Where.And(where);
                }

                newSelect = newSelect.SetWhere(where);

                select = newSelect;
            }

            return select;
        }
开发者ID:,项目名称:,代码行数:40,代码来源:


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