本文整理汇总了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;
}
示例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;
}