本文整理汇总了C#中TableAlias类的典型用法代码示例。如果您正苦于以下问题:C# TableAlias类的具体用法?C# TableAlias怎么用?C# TableAlias使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TableAlias类属于命名空间,在下文中一共展示了TableAlias类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: AddAlias
protected void AddAlias(TableAlias alias)
{
if (!this.aliasMap.ContainsKey(alias))
{
this.aliasMap.Add(alias, this.aliasMap.Count);
}
}
示例3: Visit
public override TableAlias Visit(TableAlias item)
{
if (item == null)
return null;
TableAlias result;
if (!aliasesMapping.TryGetValue(item, out result))
if (!aliasesMapping.TryGetValue(TableAlias.All, out result))
return item;
return result;
}
示例4: 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);
}
示例5: MarkColumnAsUsed
private void MarkColumnAsUsed(TableAlias alias, string name)
{
HashSet<string> columns;
if (!this.allColumnsUsed.TryGetValue(alias, out columns))
{
columns = new HashSet<string>();
this.allColumnsUsed.Add(alias, columns);
}
columns.Add(name);
}
示例6: 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;
}
}
示例7: IsColumnUsed
private bool IsColumnUsed(TableAlias alias, string name)
{
HashSet<string> columnsUsed;
if (this.allColumnsUsed.TryGetValue(alias, out columnsUsed))
{
if (columnsUsed != null)
{
return columnsUsed.Contains(name);
}
}
return false;
}
示例8: ColumnProjector
private ColumnProjector(Expression expression, IEnumerable<ColumnDeclaration> existingColumns, TableAlias newAlias, IEnumerable<TableAlias> existingAliases)
{
this.newAlias = newAlias;
this.existingAliases = new HashSet<TableAlias>(existingAliases, TableAlias.Comparer);
this.map = new Dictionary<ColumnExpression, ColumnExpression>();
if (existingColumns != null)
{
this.columns = new List<ColumnDeclaration>(existingColumns);
this.columnNames = new HashSet<string>(existingColumns.Select(c => c.Name), StringComparer.Ordinal);
}
else
{
this.columns = new List<ColumnDeclaration>();
this.columnNames = new HashSet<string>(StringComparer.Ordinal);
}
this.candidates = Nominator.Nominate(expression);
}
示例9: ColumnProjector
private ColumnProjector(Func<Expression, bool> fnCanBeColumn, Expression expression, IEnumerable<ColumnDeclaration> existingColumns, TableAlias newAlias, IEnumerable<TableAlias> existingAliases)
{
this.newAlias = newAlias;
this.existingAliases = new HashSet<TableAlias>(existingAliases);
this.map = new Dictionary<ColumnExpression, ColumnExpression>();
if (existingColumns != null)
{
this.columns = new List<ColumnDeclaration>(existingColumns);
this.columnNames = new HashSet<string>(existingColumns.Select(c => c.Name));
}
else
{
this.columns = new List<ColumnDeclaration>();
this.columnNames = new HashSet<string>();
}
this.candidates = Nominator.Nominate(fnCanBeColumn, expression);
}
示例10: 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;
}
示例11: MakeSubquery
private Expression MakeSubquery(Expression expression)
{
var newAlias = new TableAlias();
var aliases = TableAliasGatherer.Gather(expression);
var decls = new List<ColumnDeclaration>();
foreach (var ta in aliases)
{
foreach (var col in this.columns[ta])
{
string name = decls.GetAvailableColumnName(col.Name);
var decl = new ColumnDeclaration(name, col, col.SqlType);
decls.Add(decl);
var newCol = new ColumnExpression(col.Type, col.SqlType, newAlias, name);
this.map.Add(col, newCol);
}
}
return new SelectExpression(newAlias, decls, expression, null);
}
示例12: VisitTable
protected override Expression VisitTable(TableExpression table)
{
TableAlias newAlias = new TableAlias();
this.map[table.Alias] = newAlias;
return new TableExpression(newAlias, table.Entity, table.Name);
}
示例13: GetInsertExpression
public override Expression GetInsertExpression(MappingEntity entity, Expression instance, LambdaExpression selector)
{
var tables = this.mapping.GetTables(entity);
if (tables.Count < 2)
{
return base.GetInsertExpression(entity, instance, selector);
}
var commands = new List<Expression>();
var map = this.GetDependentGeneratedColumns(entity);
var vexMap = new Dictionary<MemberInfo, Expression>();
foreach (var table in this.GetDependencyOrderedTables(entity))
{
var tableAlias = new TableAlias();
var tex = new TableExpression(tableAlias, entity, this.mapping.GetTableName(table));
var assignments = this.GetColumnAssignments(tex, instance, entity,
(e, m) => this.mapping.GetAlias(e, m) == this.mapping.GetAlias(table) && !this.mapping.IsGenerated(e, m),
vexMap
);
var totalAssignments = assignments.Concat(
this.GetRelatedColumnAssignments(tex, entity, table, vexMap)
);
commands.Add(new InsertCommand(tex, totalAssignments));
List<MemberInfo> members;
if (map.TryGetValue(this.mapping.GetAlias(table), out members))
{
var d = this.GetDependentGeneratedVariableDeclaration(entity, table, members, instance, vexMap);
commands.Add(d);
}
}
if (selector != null)
{
commands.Add(this.GetInsertResult(entity, instance, selector, vexMap));
}
return new BlockCommand(commands);
}
示例14: GetDependentGeneratedVariableDeclaration
// make a variable declaration / initialization for dependent generated values
private CommandExpression GetDependentGeneratedVariableDeclaration(MappingEntity entity, MappingTable table, List<MemberInfo> members, Expression instance, Dictionary<MemberInfo, Expression> map)
{
// first make command that retrieves the generated ids if any
DeclarationCommand genIdCommand = null;
var generatedIds = this.mapping.GetMappedMembers(entity).Where(m => this.mapping.IsPrimaryKey(entity, m) && this.mapping.IsGenerated(entity, m)).ToList();
if (generatedIds.Count > 0)
{
genIdCommand = this.GetGeneratedIdCommand(entity, members, map);
// if that's all there is then just return the generated ids
if (members.Count == generatedIds.Count)
{
return genIdCommand;
}
}
// next make command that retrieves the generated members
// only consider members that were not generated ids
members = members.Except(generatedIds).ToList();
var tableAlias = new TableAlias();
var tex = new TableExpression(tableAlias, entity, this.mapping.GetTableName(table));
Expression where = null;
if (generatedIds.Count > 0)
{
where = generatedIds.Select((m, i) =>
this.GetMemberExpression(tex, entity, m).Equal(map[m])
).Aggregate((x, y) => x.And(y));
}
else
{
where = this.GetIdentityCheck(tex, entity, instance);
}
TableAlias selectAlias = new TableAlias();
var columns = new List<ColumnDeclaration>();
var variables = new List<VariableDeclaration>();
foreach (var mi in members)
{
ColumnExpression col = (ColumnExpression)this.GetMemberExpression(tex, entity, mi);
columns.Add(new ColumnDeclaration(this.mapping.GetColumnName(entity, mi), col, col.QueryType));
ColumnExpression vcol = new ColumnExpression(col.Type, col.QueryType, selectAlias, col.Name);
variables.Add(new VariableDeclaration(mi.Name, col.QueryType, vcol));
map.Add(mi, new VariableExpression(mi.Name, col.Type, col.QueryType));
}
var genMembersCommand = new DeclarationCommand(variables, new SelectExpression(selectAlias, columns, tex, where));
if (genIdCommand != null)
{
return new BlockCommand(genIdCommand, genMembersCommand);
}
return genMembersCommand;
}
示例15: GetInsertExpression
public override Expression GetInsertExpression(MappingEntity entity, Expression instance, LambdaExpression selector)
{
var tableAlias = new TableAlias();
var table = new TableExpression(tableAlias, entity, this.mapping.GetTableName(entity));
var assignments = this.GetColumnAssignments(table, instance, entity, (e, m) => !this.mapping.IsGenerated(e, m));
if (selector != null)
{
return new BlockCommand(
new InsertCommand(table, assignments),
this.GetInsertResult(entity, instance, selector, null)
);
}
return new InsertCommand(table, assignments);
}