Files
sql-utilities/src/Strata.SqlTools.SqlBreakdown/Classes/SqlFrom.cs
T
Thom LambandClaude Opus 4.7 0f8d505616
SonarQube Analysis / sonarqube (pull_request) Successful in 2m47s
chore(sonar): apply collection-expression syntax across all sites (IDE0028)
Manual sweep of all 42 IDE0028 sites flagged by SonarQube — `dotnet format
analyzers --diagnostics IDE0028` declined to fix these (no .editorconfig
opt-in for `dotnet_style_prefer_collection_expression`), so applied by
hand. The repo already targets `<LangVersion>latest</LangVersion>` on
net8.0, so C# 12 collection expressions are available.

Pattern: `new List<T>()` / `new Dictionary<K,V>()` / `new ArrayList()` /
`new()` -> `[]` for empty; `new List<T> { ... }` -> `[...]` for literal.

24 files touched in src/{EFCore, LinqToSql, Query, Snowflake, SqlBreakdown,
SqlServer}; tests untouched (no IDE0028 sites in test code).

Build clean (35 warnings unchanged from baseline, 0 errors). All tests
remain green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 17:01:30 -05:00

64 lines
2.1 KiB
C#

using Strata.SqlTools.SqlBreakdown.Extensions;
namespace Strata.SqlTools.SqlBreakdown.Classes;
/// <summary>
/// Represents a SQL FROM clause with optional JOIN clauses.
/// </summary>
public class SqlFrom
{
private readonly SqlTable _firstTable;
private readonly List<SqlJoin> _joins;
/// <summary>
/// Initializes a new instance of the <see cref="SqlFrom"/> class.
/// </summary>
/// <param name="tableExpression">The primary table expression.</param>
/// <param name="tableAlias">The primary table alias.</param>
public SqlFrom(string tableExpression, string tableAlias)
{
_firstTable = new SqlTable(tableExpression, tableAlias);
_joins = [];
}
/// <summary>
/// Adds a JOIN to the FROM clause.
/// </summary>
/// <param name="table2Expression">The table expression to join.</param>
/// <param name="table2Alias">The alias for the joined table.</param>
/// <param name="table1Column">The column from the primary table.</param>
/// <param name="table2Column">The column from the joined table.</param>
public void Join(string table2Expression, string table2Alias, string table1Column, string table2Column)
{
var theJoin = new SqlJoin(table2Expression, table2Alias, table1Column, table2Column);
Join(theJoin);
}
/// <summary>
/// Adds a pre-constructed JOIN to the FROM clause.
/// </summary>
/// <param name="join">The join to add.</param>
public void Join(SqlJoin join)
{
_joins.Add(join);
}
/// <summary>
/// Returns the SQL FROM clause as a string.
/// </summary>
/// <returns>The FROM clause with all JOINs.</returns>
public override string ToString()
{
var output = new StringBuilderEx();
output.AppendFormat($"\t{_firstTable.TableExpression} {_firstTable.TableAlias}\n");
foreach (var join in _joins)
{
output.AppendFormat($"\tINNER JOIN {join.TableExpression} {join.TableAlias} ON {join.GetJoinOn(_firstTable.TableAlias)}\n");
}
return output.ToString();
}
}