Skip to content

Commit

Permalink
Merge pull request #544 from mk3008/develop
Browse files Browse the repository at this point in the history
Fix: Adjusted column alias handling in Select method to avoid empty alias.
  • Loading branch information
mk3008 authored Oct 14, 2024
2 parents e2727d5 + a70edab commit 85475e6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Carbunql/Fluent/SelectQuerySelectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,18 @@ public static SelectQuery SelectOnlyByNames(this SelectQuery query, IEnumerable<
return query;
}

/// <summary>
/// Adds a column selection to the query with an optional alias.
/// If the provided alias is null or empty, the column name will be used as the alias.
/// </summary>
/// <param name="query">The current SelectQuery object.</param>
/// <param name="tableAlias">The alias of the table that contains the column.</param>
/// <param name="column">The name of the column to select.</param>
/// <param name="columnAlias">Optional alias for the column. If not provided or empty, the column name will be used.</param>
/// <returns>The updated SelectQuery object.</returns>
public static SelectQuery Select(this SelectQuery query, string tableAlias, string column, string columnAlias = "")
{
query.AddSelect($"{tableAlias}.{column}", columnAlias);
query.AddSelect($"{tableAlias}.{column}", string.IsNullOrEmpty(columnAlias) ? column : columnAlias);
return query;
}

Expand Down

0 comments on commit 85475e6

Please sign in to comment.