本文整理汇总了C#中ProjectionExpression类的典型用法代码示例。如果您正苦于以下问题:C# ProjectionExpression类的具体用法?C# ProjectionExpression怎么用?C# ProjectionExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProjectionExpression类属于命名空间,在下文中一共展示了ProjectionExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
}
示例2: VisitProjection
protected override Expression VisitProjection(ProjectionExpression proj)
{
if (proj != root)
return AliasReplacer.Replace(base.VisitProjection(proj), aliasGenerator);
else
return (ProjectionExpression)base.VisitProjection(proj);
}
示例3: ProviderQueryExpression
public ProviderQueryExpression(
IEnumerable<ProviderPropertyExpression> providerProperties,
ProjectionExpression projection,
PredicateExpression predicate,
SortExpressionCollectionExpression sort)
: this(new ProviderPropertiesExpression(providerProperties), projection, predicate, sort)
{ }
示例4: AddOuterJoinTest
public virtual ProjectionExpression AddOuterJoinTest(ProjectionExpression proj)
{
var test = this.GetOuterJoinTest(proj.Select);
var select = proj.Select;
ColumnExpression testCol = null;
// look to see if test expression exists in columns already
foreach (var col in select.Columns)
{
if (test.Equals(col.Expression))
{
var colType = SqlType.Get(test.Type);
testCol = new ColumnExpression(test.Type, colType, select.Alias, col.Name);
break;
}
}
if (testCol == null)
{
// add expression to projection
testCol = test as ColumnExpression;
string colName = (testCol != null) ? testCol.Name : "Test";
colName = proj.Select.Columns.GetAvailableColumnName(colName);
var colType = SqlType.Get(test.Type);
select = select.AddColumn(new ColumnDeclaration(colName, test, colType));
testCol = new ColumnExpression(test.Type, colType, select.Alias, colName);
}
var newProjector = new OuterJoinedExpression(testCol, proj.Projector);
return new ProjectionExpression(select, newProjector, proj.Aggregator);
}
示例5: UpdateClientJoin
protected ClientJoinExpression UpdateClientJoin(ClientJoinExpression join, ProjectionExpression projection, IEnumerable<Expression> outerKey, IEnumerable<Expression> innerKey)
{
if (projection != join.Projection || outerKey != join.OuterKey || innerKey != join.InnerKey)
{
return new ClientJoinExpression(projection, outerKey, innerKey);
}
return join;
}
示例6: VisitProjection
protected override Expression VisitProjection(ProjectionExpression proj)
{
// don't parameterize the projector or aggregator!
SelectExpression select = (SelectExpression)this.Visit(proj.Source);
if (select != proj.Source) {
return new ProjectionExpression(select, proj.Projector, proj.Aggregator);
}
return proj;
}
示例7: VisitProjection
protected override Expression VisitProjection(ProjectionExpression proj)
{
Expression projector = this.Visit(proj.Projector);
if (projector != proj.Projector)
{
return new ProjectionExpression(proj.Source, projector, proj.Aggregator);
}
return proj;
}
示例8: VisitProjection
protected override Expression VisitProjection(ProjectionExpression proj)
{
SelectExpression save = this.currentSelect;
this.currentSelect = proj.Source;
try
{
if (!this.isTopLevel)
{
if (this.CanJoinOnClient(this.currentSelect))
{
// make a query that combines all the constraints from the outer queries into a single select
SelectExpression newOuterSelect = (SelectExpression)QueryDuplicator.Duplicate(save);
// remap any references to the outer select to the new alias;
SelectExpression newInnerSelect = (SelectExpression)ColumnMapper.Map(proj.Source, newOuterSelect.Alias, save.Alias);
// add outer-join test
ProjectionExpression newInnerProjection = new ProjectionExpression(newInnerSelect, proj.Projector).AddOuterJoinTest();
newInnerSelect = newInnerProjection.Source;
Expression newProjector = newInnerProjection.Projector;
TableAlias newAlias = new TableAlias();
var pc = ColumnProjector.ProjectColumns(this.language.CanBeColumn, newProjector, newOuterSelect.Columns, newAlias, newOuterSelect.Alias, newInnerSelect.Alias);
JoinExpression join = new JoinExpression(JoinType.OuterApply, newOuterSelect, newInnerSelect, null);
SelectExpression joinedSelect = new SelectExpression(newAlias, pc.Columns, join, null, null, null, proj.IsSingleton, null, null);
// apply client-join treatment recursively
this.currentSelect = joinedSelect;
newProjector = this.Visit(pc.Projector);
// compute keys (this only works if join condition was a single column comparison)
List<Expression> outerKeys = new List<Expression>();
List<Expression> innerKeys = new List<Expression>();
if (this.GetEquiJoinKeyExpressions(newInnerSelect.Where, newOuterSelect.Alias, outerKeys, innerKeys))
{
// outerKey needs to refer to the outer-scope's alias
var outerKey = outerKeys.Select(k => ColumnMapper.Map(k, save.Alias, newOuterSelect.Alias));
// innerKey needs to refer to the new alias for the select with the new join
var innerKey = innerKeys.Select(k => ColumnMapper.Map(k, joinedSelect.Alias, ((ColumnExpression)k).Alias));
ProjectionExpression newProjection = new ProjectionExpression(joinedSelect, newProjector, proj.Aggregator);
return new ClientJoinExpression(newProjection, outerKey, innerKey);
}
}
}
else
{
this.isTopLevel = false;
}
return base.VisitProjection(proj);
}
finally
{
this.currentSelect = save;
}
}
示例9: Flatten
static internal ProjectionExpression Flatten(ProjectionExpression proj, AliasGenerator aliasGenerator)
{
var result = (ProjectionExpression)new ChildProjectionFlattener { aliasGenerator = aliasGenerator }.Visit(proj);
if (result == proj)
return result;
Expression columnCleaned = UnusedColumnRemover.Remove(result);
Expression subqueryCleaned = RedundantSubqueryRemover.Remove(columnCleaned);
return (ProjectionExpression)subqueryCleaned;
}
示例10: VisitProjection
protected override Expression VisitProjection(ProjectionExpression projection)
{
// visit mapping in reverse order
Expression projector = this.Visit(projection.Projector);
SelectExpression source = (SelectExpression)this.Visit(projection.Source);
if (projector != projection.Projector || source != projection.Source)
{
return new ProjectionExpression(source, projector, projection.Aggregator);
}
return projection;
}
示例11: MergeProjectionExpressions
private static ProjectionExpression MergeProjectionExpressions(ProjectionExpression projection,
ProjectionExpression expression)
{
if (projection is AttributesProjectionExpression && expression is AttributesProjectionExpression)
{
List<PropertyNameExpression> expr = new List<PropertyNameExpression>();
expr.AddRange((projection as AttributesProjectionExpression).Attributes.Collection);
expr.AddRange((expression as AttributesProjectionExpression).Attributes.Collection);
return new AttributesProjectionExpression(expr);
}
throw GetMergeException(projection, expression);
}
示例12: VisitProjection
protected override Expression VisitProjection(ProjectionExpression proj)
{
this.Visit(proj.Projector);
SelectExpression source = (SelectExpression)this.Visit(proj.Select);
Expression projector = this.Visit(proj.Projector);
if (source != proj.Select || projector != proj.Projector)
{
return new ProjectionExpression(source, projector, proj.UniqueFunction, proj.Type);
}
return proj;
}
示例13: VisitClientJoin
protected override Expression VisitClientJoin(ClientJoinExpression join)
{
// convert client join into a up-front lookup table builder & replace client-join in tree with lookup accessor
// 1) lookup = query.Select(e => new KVP(key: inner, value: e)).ToLookup(kvp => kvp.Key, kvp => kvp.Value)
Expression innerKey = MakeJoinKey(join.InnerKey);
Expression outerKey = MakeJoinKey(join.OuterKey);
ConstructorInfo kvpConstructor = typeof(KeyValuePair<,>).MakeGenericType(innerKey.Type, join.Projection.Projector.Type).GetConstructor(new System.Type[] { innerKey.Type, join.Projection.Projector.Type });
Expression constructKVPair = Expression.New(kvpConstructor, innerKey, join.Projection.Projector);
ProjectionExpression newProjection = new ProjectionExpression(join.Projection.Source, constructKVPair);
int iLookup = ++nLookup;
Expression execution = ExecuteProjection(newProjection, false);
ParameterExpression kvp = Expression.Parameter(constructKVPair.Type, "kvp");
// filter out nulls
if (join.Projection.Projector.NodeType == (ExpressionType)DbExpressionType.OuterJoined)
{
LambdaExpression pred = Expression.Lambda(
Expression.NotEqual(
Expression.PropertyOrField(kvp, "Value"),
Expression.Constant(null, join.Projection.Projector.Type)
),
kvp
);
execution = Expression.Call(typeof(Enumerable), "Where", new System.Type[] { kvp.Type }, execution, pred);
}
// make lookup
LambdaExpression keySelector = Expression.Lambda(Expression.PropertyOrField(kvp, "Key"), kvp);
LambdaExpression elementSelector = Expression.Lambda(Expression.PropertyOrField(kvp, "Value"), kvp);
Expression toLookup = Expression.Call(typeof(Enumerable), "ToLookup", new System.Type[] { kvp.Type, outerKey.Type, join.Projection.Projector.Type }, execution, keySelector, elementSelector);
// 2) agg(lookup[outer])
ParameterExpression lookup = Expression.Parameter(toLookup.Type, "lookup" + iLookup);
PropertyInfo property = lookup.Type.GetProperty("Item");
Expression access = Expression.Call(lookup, property.GetGetMethod(), Visit(outerKey));
if (join.Projection.Aggregator != null)
{
// apply aggregator
access = DbExpressionReplacer.Replace(join.Projection.Aggregator.Body, join.Projection.Aggregator.Parameters[0], access);
}
variables.Add(lookup);
initializers.Add(toLookup);
return access;
}
示例14: VisitProjection
protected virtual Expression VisitProjection(ProjectionExpression projection)
{
this.AddAlias(projection.Source.Alias);
this.Write("Project(");
this.WriteLine(Indentation.Inner);
this.Write("@\"");
this.Visit(projection.Source);
this.Write("\",");
this.WriteLine(Indentation.Same);
this.Visit(projection.Projector);
this.Write(",");
this.WriteLine(Indentation.Same);
this.Visit(projection.Aggregator);
this.WriteLine(Indentation.Outer);
this.Write(")");
return projection;
}
示例15: VisitProjection
protected override Expression VisitProjection(ProjectionExpression proj)
{
if (isTopLevel)
{
isTopLevel = false;
currentSelect = proj.Source;
Expression projector = Visit(proj.Projector);
if (projector != proj.Projector || currentSelect != proj.Source)
{
return new ProjectionExpression(currentSelect, projector, proj.Aggregator);
}
return proj;
}
if (proj.IsSingleton && CanJoinOnServer(currentSelect))
{
TableAlias newAlias = new TableAlias();
currentSelect = currentSelect.AddRedundantSelect(newAlias);
// remap any references to the outer select to the new alias;
SelectExpression source =
(SelectExpression) ColumnMapper.Map(proj.Source, newAlias, currentSelect.Alias);
// add outer-join test
ProjectionExpression pex = new ProjectionExpression(source, proj.Projector).AddOuterJoinTest();
var pc = ColumnProjector.ProjectColumns(language.CanBeColumn, pex.Projector, currentSelect.Columns,
currentSelect.Alias, newAlias, proj.Source.Alias);
JoinExpression join = new JoinExpression(JoinType.OuterApply, currentSelect.From, pex.Source, null);
currentSelect = new SelectExpression(currentSelect.Alias, pc.Columns, join, null);
return Visit(pc.Projector);
}
var saveTop = isTopLevel;
var saveSelect = currentSelect;
isTopLevel = true;
currentSelect = null;
Expression result = base.VisitProjection(proj);
isTopLevel = saveTop;
currentSelect = saveSelect;
return result;
}