本文整理汇总了C#中SelectExpression类的典型用法代码示例。如果您正苦于以下问题:C# SelectExpression类的具体用法?C# SelectExpression怎么用?C# SelectExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SelectExpression类属于命名空间,在下文中一共展示了SelectExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitSelect
protected override Expression VisitSelect(SelectExpression select)
{
if (this.selectsToRemove.Contains(select))
return this.Visit(select.From);
else
return base.VisitSelect(select);
}
示例2: VisitSelect
protected override Expression VisitSelect(SelectExpression select)
{
var saveFrom = this.currentFrom;
var saveInAggregate = this.inAggregate;
this.inAggregate = false;
SourceExpression from = this.VisitSource(select.From);
this.currentFrom = from;
Expression top = this.Visit(select.Top);
Expression where = this.Visit(select.Where);
ReadOnlyCollection<ColumnDeclaration> columns = select.Columns.NewIfChange(VisitColumnDeclaration);
ReadOnlyCollection<OrderExpression> orderBy = select.OrderBy.NewIfChange(VisitOrderBy);
ReadOnlyCollection<Expression> groupBy = select.GroupBy.NewIfChange(Visit);
from = this.currentFrom;
this.inAggregate = saveInAggregate;
this.currentFrom = saveFrom;
if (top != select.Top || from != select.From || where != select.Where || columns != select.Columns || orderBy != select.OrderBy || groupBy != select.GroupBy)
return new SelectExpression(select.Alias, select.IsDistinct, top, columns, from, where, orderBy, groupBy, select.SelectOptions);
return select;
}
示例3: GetOuterJoinTest
public static Expression GetOuterJoinTest(SelectExpression select)
{
// if the column is used in the join condition (equality test)
// if it is null in the database then the join test won't match (null != null) so the row won't appear
// we can safely use this existing column as our test to determine if the outer join produced a row
// find a column that is used in equality test
var aliases = DeclaredAliasGatherer.Gather(select.From);
var joinColumns = JoinColumnGatherer.Gather(aliases, select).ToList();
if (joinColumns.Count > 0)
{
// prefer one that is already in the projection list.
foreach (var jc in joinColumns)
{
foreach (var col in select.Columns)
{
if (jc.Equals(col.Expression))
{
return jc;
}
}
}
return joinColumns[0];
}
// fall back to introducing a constant
return Expression.Constant(1, typeof(int?));
}
示例4: VisitSelect
protected override Expression VisitSelect(SelectExpression select)
{
TableAlias newAlias = new TableAlias();
this.map[select.Alias] = newAlias;
select = (SelectExpression)base.VisitSelect(select);
return new SelectExpression(newAlias, select.Columns, select.From, select.Where, select.OrderBy, select.GroupBy, select.IsDistinct, select.Skip, select.Take, select.IsReverse);
}
示例5: VisitSelect
protected internal override Expression VisitSelect(SelectExpression select)
{
// visit column projection first
HashSet<string> columnsUsed = allColumnsUsed.GetOrCreate(select.Alias); // a veces no se usa
ReadOnlyCollection<ColumnDeclaration> columns = select.Columns.Select(c =>
{
if (select.IsDistinct ? IsConstant(c.Expression) : !columnsUsed.Contains(c.Name))
return null;
var ex = Visit(c.Expression);
return ex == c.Expression ? c : new ColumnDeclaration(c.Name, ex);
}).NotNull().ToReadOnly();
ReadOnlyCollection<OrderExpression> orderbys = Visit(select.OrderBy, VisitOrderBy);
Expression where = this.Visit(select.Where);
ReadOnlyCollection<Expression> groupBy = select.GroupBy.Select(e => IsConstant(e) ? null : Visit(e)).NotNull().ToReadOnly();
SourceExpression from = this.VisitSource(select.From);
if (columns != select.Columns || orderbys != select.OrderBy || where != select.Where || from != select.From || groupBy != select.GroupBy)
return new SelectExpression(select.Alias, select.IsDistinct, select.Top, columns, from, where, orderbys, groupBy, select.SelectOptions);
return select;
}
示例6: VisitSelect
protected override Expression VisitSelect(SelectExpression select)
{
select = (SelectExpression)base.VisitSelect(select);
if (lookup.Contains(select.Alias))
{
List<ColumnDeclaration> aggColumns = new List<ColumnDeclaration>(select.Columns);
foreach (AggregateSubqueryExpression ae in lookup[select.Alias])
{
string name = "agg" + aggColumns.Count;
var colType = DbTypeSystem.GetColumnType(ae.Type);
ColumnDeclaration cd = new ColumnDeclaration(name, ae.AggregateInGroupSelect, colType);
this.map.Add(ae, new ColumnExpression(ae.Type, colType, ae.GroupByAlias, name));
aggColumns.Add(cd);
}
return new SelectExpression(
select.Alias,
aggColumns,
select.From,
select.Where,
select.OrderBy,
select.GroupBy,
select.IsDistinct,
select.Skip,
select.Take,
select.IsReverse);
}
return select;
}
示例7: VisitProjection
protected override Expression VisitProjection(ProjectionExpression proj)
{
using (Scope())
{
var oldOuterMostSelect = outerMostSelect;
outerMostSelect = proj.Select;
var oldHasProjectionInProjector = hasProjectionInProjector;
hasProjectionInProjector = false;
Expression projector = this.Visit(proj.Projector);
SelectExpression source = (SelectExpression)this.Visit(proj.Select);
hasProjectionInProjector = oldHasProjectionInProjector;
hasProjectionInProjector |= true;
outerMostSelect = oldOuterMostSelect;
if (source != proj.Select || projector != proj.Projector)
return new ProjectionExpression(source, projector, proj.UniqueFunction, proj.Type);
return proj;
}
}
示例8: VisitIn
protected override Expression VisitIn(InExpression expression)
{
if (!ShouldRewrite(expression)) {
return base.VisitIn(expression);
}
Array array = expression.Values.OfType<ConstantExpression>().Select(item => item.Value).Distinct().ToArray();
var vfpDataXml = new ArrayXmlToCursor(array);
var tableAlias = new TableAlias();
var columnType = _language.TypeSystem.GetColumnType(vfpDataXml.ItemType);
var columnExpression = new ColumnExpression(vfpDataXml.ItemType, columnType, tableAlias, ArrayXmlToCursor.ColumnName);
var columns = new List<ColumnDeclaration> {
new ColumnDeclaration(string.Empty, columnExpression, columnType)
};
var xml = Expression.Constant(vfpDataXml.Xml);
var cursorName = Expression.Constant("curTemp_" + DateTime.Now.ToString("ddHHssmm"));
var check = Expression.GreaterThan(new XmlToCursorExpression(xml, cursorName), Expression.Constant(0));
var from = Expression.Condition(check, cursorName, Expression.Constant(string.Empty));
var select = new SelectExpression(tableAlias, columns, from, null);
return new InExpression(expression.Expression, select);
}
示例9: VisitSelect
protected override Expression VisitSelect(SelectExpression select)
{
Expression saveCurrentFrom = this.currentFrom;
this.currentFrom = this.VisitSource(select.From);
try
{
Expression where = this.Visit(select.Where);
ReadOnlyCollection<OrderExpression> orderBy = this.VisitOrderBy(select.OrderBy);
ReadOnlyCollection<Expression> groupBy = this.VisitExpressionList(select.GroupBy);
Expression skip = this.Visit(select.Skip);
Expression take = this.Visit(select.Take);
ReadOnlyCollection<ColumnDeclaration> columns = this.VisitColumnDeclarations(select.Columns);
if (this.currentFrom != select.From
|| where != select.Where
|| orderBy != select.OrderBy
|| groupBy != select.GroupBy
|| take != select.Take
|| skip != select.Skip
|| columns != select.Columns
)
{
return new SelectExpression(select.Alias, columns, this.currentFrom, where, orderBy, groupBy, select.IsDistinct, skip, take, select.IsReverse);
}
return select;
}
finally
{
this.currentFrom = saveCurrentFrom;
}
}
示例10: VisitSelect
protected override Expression VisitSelect(SelectExpression select)
{
if (first) {
first = false;
return base.VisitSelect(select);
}
return select;
}
示例11: VisitSelect
protected override Expression VisitSelect(SelectExpression select)
{
// only consider aggregates in these locations
this.Visit(select.Where);
this.VisitOrderBy(select.OrderBy);
this.VisitColumnDeclarations(select.Columns);
return select;
}
示例12: UpdateDeclaration
protected DeclarationCommand UpdateDeclaration(DeclarationCommand decl, IEnumerable<VariableDeclaration> variables, SelectExpression source)
{
if (variables != decl.Variables || source != decl.Source)
{
return new DeclarationCommand(variables, source);
}
return decl;
}
示例13: VisitSelect
protected override Expression VisitSelect(SelectExpression select)
{
bool saveIsOuterMostSelect = this.isOuterMostSelect;
try
{
this.isOuterMostSelect = false;
select = (SelectExpression)base.VisitSelect(select);
bool hasOrderBy = select.OrderBy != null && select.OrderBy.Count > 0;
bool hasGroupBy = select.GroupBy != null && select.GroupBy.Count > 0;
bool canHaveOrderBy = saveIsOuterMostSelect || select.Take != null || select.Skip != null;
bool canReceiveOrderings = canHaveOrderBy && !hasGroupBy && !select.IsDistinct;
if (hasOrderBy)
{
this.PrependOrderings(select.OrderBy);
}
IEnumerable<OrderExpression> orderings = null;
if (canReceiveOrderings)
{
orderings = this.gatheredOrderings;
}
else if (canHaveOrderBy)
{
orderings = select.OrderBy;
}
bool canPassOnOrderings = !saveIsOuterMostSelect && !hasGroupBy && !select.IsDistinct;
ReadOnlyCollection<ColumnDeclaration> columns = select.Columns;
if (this.gatheredOrderings != null)
{
if (canPassOnOrderings)
{
var producedAliases = DeclaredAliasGatherer.Gather(select.From);
// reproject order expressions using this select's alias so the outer select will have properly formed expressions
BindResult project = this.RebindOrderings(this.gatheredOrderings, select.Alias, producedAliases, select.Columns);
this.gatheredOrderings = null;
this.PrependOrderings(project.Orderings);
columns = project.Columns;
}
else
{
this.gatheredOrderings = null;
}
}
if (orderings != select.OrderBy || columns != select.Columns)
{
select = new SelectExpression(select.Alias, columns, select.From, select.Where, orderings, select.GroupBy, select.IsDistinct, select.Skip, select.Take);
}
return select;
}
finally
{
this.isOuterMostSelect = saveIsOuterMostSelect;
}
}
示例14: AddRedundantSelect
public static SelectExpression AddRedundantSelect(this SelectExpression sel, QueryLanguage language, TableAlias newAlias)
{
var newColumns =
from d in sel.Columns
let qt = (d.Expression is ColumnExpression) ? ((ColumnExpression)d.Expression).QueryType : language.TypeSystem.GetColumnType(d.Expression.Type)
select new ColumnDeclaration(d.Name, new ColumnExpression(d.Expression.Type, qt, newAlias, d.Name), qt);
var newFrom = new SelectExpression(newAlias, sel.Columns, sel.From, sel.Where, sel.OrderBy, sel.GroupBy, sel.IsDistinct, sel.Skip, sel.Take, sel.IsReverse);
return new SelectExpression(sel.Alias, newColumns, newFrom, null, null, null, false, null, null, false);
}
示例15: IsSimpleProjection
internal static bool IsSimpleProjection(SelectExpression select)
{
foreach (ColumnDeclaration decl in select.Columns) {
ColumnExpression col = decl.Expression as ColumnExpression;
if (col == null || decl.Name != col.Name) {
return false;
}
}
return true;
}