string GetClausesForJoinQuery(string select, bool orderby) { var leftTableAlias = tableAliasGenerator.GenerateTableAlias(ViewOrTableName); var sb = new StringBuilder(); sb.AppendFormat(select, leftTableAlias) .AppendLine($" FROM (SELECT * {GetClauses(false)}) {leftTableAlias}"); foreach (var join in Joins) { var right = join.RightQuery; var rightQuery = right.SelectQuery(false); var rightTableAlias = tableAliasGenerator.GenerateTableAlias(right.ViewOrTableName); var joinClauseString = JoinClauseString(leftTableAlias, rightTableAlias, join.JoinClauses); var joinTypeString = JoinTypeString(join.JoinType); sb.AppendLine($"{joinTypeString} ({rightQuery}) {rightTableAlias} {joinClauseString}"); } if (orderby) { var orderByClause = GetOrderByClause(leftTableAlias); if (!string.IsNullOrEmpty(orderByClause)) { sb.AppendLine(orderByClause); } } return(sb.ToString().Trim()); }
public IJoinSourceQueryBuilder <TRecord> Join(IAliasedSelectSource source, JoinType joinType, CommandParameterValues parameterValues, Parameters parameters, ParameterDefaults parameterDefaults) { var clonedSelectBuilder = selectBuilder.Clone(); clonedSelectBuilder.IgnoreDefaultOrderBy(); var subquery = new SubquerySource(clonedSelectBuilder.GenerateSelect(), tableAliasGenerator.GenerateTableAlias()); return(new JoinSourceQueryBuilder <TRecord>(subquery, joinType, source, transaction, tableAliasGenerator, uniqueParameterNameGenerator, new CommandParameterValues(ParameterValues, parameterValues), new Parameters(Parameters, parameters), new ParameterDefaults(ParameterDefaults, parameterDefaults))); }
string GetAlias() { if (string.IsNullOrEmpty(customAlias)) { customAlias = tableAliasGenerator.GenerateTableAlias(); } return(customAlias); }
public QueryBuilderFixture() { transaction = Substitute.For <IRelationalTransaction>(); var tableNumber = 0; tableAliasGenerator.GenerateTableAlias(Arg.Any <string>()).Returns(delegate { tableNumber++; return("t" + tableNumber); }); }
public IJoinSourceQueryBuilder <TRecord> Join(IAliasedSelectSource source, JoinType joinType, CommandParameterValues parameterValues, Parameters parameters, ParameterDefaults parameterDefaults) { var subquery = new SubquerySource(selectBuilder.GenerateSelectWithoutDefaultOrderBy(), tableAliasGenerator.GenerateTableAlias()); return(new JoinSourceQueryBuilder <TRecord>(subquery, joinType, source, readQueryExecutor, tableAliasGenerator, uniqueParameterNameGenerator, new CommandParameterValues(ParameterValues, parameterValues), new Parameters(Parameters, parameters), new ParameterDefaults(ParameterDefaults, parameterDefaults))); }