本文整理汇总了C#中IQueryContext.TableExists方法的典型用法代码示例。如果您正苦于以下问题:C# IQueryContext.TableExists方法的具体用法?C# IQueryContext.TableExists怎么用?C# IQueryContext.TableExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IQueryContext
的用法示例。
在下文中一共展示了IQueryContext.TableExists方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrepareStatement
protected override SqlPreparedStatement PrepareStatement(IExpressionPreparer preparer, IQueryContext context)
{
var tableName = context.ResolveTableName(TableName);
if (!context.TableExists(tableName))
throw new ObjectNotFoundException(tableName);
var queryExpression = new SqlQueryExpression(new[]{SelectColumn.Glob("*") });
queryExpression.FromClause.AddTable(tableName.FullName);
queryExpression.WhereExpression = WherExpression;
var queryFrom = QueryExpressionFrom.Create(context, queryExpression);
var queryPlan = context.DatabaseContext().QueryPlanner().PlanQuery(context, queryExpression, null);
var columns = new List<SqlAssignExpression>();
foreach (var assignment in Assignments) {
var columnName = ObjectName.Parse(assignment.ColumnName);
var refName = queryFrom.ResolveReference(columnName);
var expression = assignment.Expression.Prepare(queryFrom.ExpressionPreparer);
var assign = SqlExpression.Assign(SqlExpression.Reference(refName), expression);
columns.Add(assign);
}
return new Prepared(tableName, queryPlan, columns.ToArray(), Limit);
}
示例2: Create
public static QueryExpressionFrom Create(IQueryContext context, SqlQueryExpression expression)
{
// Get the 'from_clause' from the table expression
var fromClause = expression.FromClause;
var ignoreCase = context.IgnoreIdentifiersCase();
var queryFrom = new QueryExpressionFrom(ignoreCase);
foreach (var fromTable in fromClause.AllTables) {
var uniqueKey = fromTable.UniqueKey;
var alias = fromTable.Alias;
if (fromTable.IsSubQuery) {
// eg. FROM ( SELECT id FROM Part )
var subQuery = fromTable.SubQuery;
var subQueryFrom = Create(context, subQuery);
// The aliased name of the table
ObjectName aliasTableName = null;
if (alias != null)
aliasTableName = new ObjectName(alias);
// Add to list of sub-query tables to add to command,
queryFrom.AddTable(new FromTableSubQuerySource(ignoreCase, uniqueKey, subQuery, subQueryFrom, aliasTableName));
} else {
// Else must be a standard command table,
string name = fromTable.Name;
// Resolve to full table name
var tableName = context.ResolveTableName(name);
if (!context.TableExists(tableName))
throw new InvalidOperationException(String.Format("Table '{0}' was not found.", tableName));
ObjectName givenName = null;
if (alias != null)
givenName = new ObjectName(alias);
// Get the ITableQueryInfo object for this table name (aliased).
ITableQueryInfo tableQueryInfo = context.GetTableQueryInfo(tableName, givenName);
queryFrom.AddTable(new FromTableDirectSource(ignoreCase, tableQueryInfo, uniqueKey, givenName, tableName));
}
}
// Set up functions, aliases and exposed variables for this from set,
foreach (var selectColumn in expression.SelectColumns) {
// Is this a glob? (eg. Part.* )
if (selectColumn.IsGlob) {
// Find the columns globbed and add to the 'selectedColumns' result.
if (selectColumn.IsAll) {
queryFrom.ExposeAllColumns();
} else {
// Otherwise the glob must be of the form '[table name].*'
queryFrom.ExposeColumns(selectColumn.TableName);
}
} else {
// Otherwise must be a standard column reference. Note that at this
// time we aren't sure if a column expression is correlated and is
// referencing an outer source. This means we can't verify if the
// column expression is valid or not at this point.
// If this column is aliased, add it as a function reference to the
// select expression
string alias = selectColumn.Alias;
var v = selectColumn.Expression.AsReferenceName();
bool aliasMatchV = (v != null && alias != null &&
queryFrom.CompareStrings(v.Name, alias));
if (alias != null && !aliasMatchV) {
queryFrom.AddExpression(new ExpressionReference(selectColumn.Expression, alias));
queryFrom.ExposeColumn(new ObjectName(alias));
} else if (v != null) {
var resolved = queryFrom.ResolveReference(v);
queryFrom.ExposeColumn(resolved ?? v);
} else {
string funName = selectColumn.Expression.ToString();
queryFrom.AddExpression(new ExpressionReference(selectColumn.Expression, funName));
queryFrom.ExposeColumn(new ObjectName(funName));
}
}
}
return queryFrom;
}