public override string BuildFromString(BuildMapState state, ISqlSyntax sqlFragmentBuilder, string wrappedQueryAlias = null) { var tableIsFirstParamPart = wrappedQueryAlias == null; var table1 = (First.Param ?? "").StartsWith("@") ? null : wrappedQueryAlias; return(Next.Aggregate( BuildColumn(table1, First), Aggregate)); string Aggregate(string x, (StringBasedElement param, BinarySqlOperator type) y) { var table = (y.param.Param ?? "").StartsWith("@") ? null : wrappedQueryAlias; var yValue = BuildColumn(table, y.param); return(ISqlExpressionUtils.Combine(sqlFragmentBuilder, x, yValue, y.type)); } string BuildColumn(string tab, StringBasedElement el) { var column = el.AddRoot(state).param; if (tableIsFirstParamPart) { var p = column.Split('.'); if (p.Length > 1) { tab = p.Take(p.Length - 1).JoinString("."); column = p[p.Length - 1]; } } return(sqlFragmentBuilder.BuildSelectColumn(tab, column)); } }
public string BuildFromString(BuildMapState state, ISqlSyntax sqlFragmentBuilder, string wrappedQueryAlias = null) { var first = First.BuildFromString(state, sqlFragmentBuilder, wrappedQueryAlias); return(AddUnaryCondition( sqlFragmentBuilder, first, Operator, First.HasOneItemOnly)); }
public MappedSqlStatementBuilder( BuildMapState state, IEnumerable <QueryElementBasedMappedProperty> selectProperties, ISqlSelectStatement statement, ISqlString innerSqlString, ISqlSyntax sqlSyntax) { State = state ?? throw new ArgumentNullException(nameof(state)); SelectProperties = selectProperties?.ToDictionary(x => x.To) ?? throw new ArgumentNullException(nameof(selectProperties)); Statement = statement ?? throw new ArgumentNullException(nameof(statement)); InnerSqlString = innerSqlString ?? throw new ArgumentNullException(nameof(innerSqlString)); SqlSyntax = sqlSyntax ?? throw new ArgumentNullException(nameof(innerSqlString)); // this paradigm can be extended if there are more than 1 // alias needed per query InnerQueryAlias = SqlStatementConstants.InnerQueryAlias; }
public override string BuildFromString(BuildMapState state, ISqlSyntax sqlFragmentBuilder, string wrappedQueryAlias = null) { return(Next.Aggregate( BuildColumn(First), Aggregate)); string Aggregate(string x, (SelectColumnBasedElement param, BinarySqlOperator type) y) { var yValue = BuildColumn(y.param); return(ISqlExpressionUtils.Combine(sqlFragmentBuilder, x, yValue, y.type)); } string BuildColumn(SelectColumnBasedElement el) { return(sqlFragmentBuilder.BuildSelectColumn( el.IsParameter ? null : wrappedQueryAlias, el.IsParameter ? el.ParameterName : el.Column.Alias)); } }