chore(sonar)!: return empty IQueryable instead of null from GetQuery<T> (S1168)
Replaces `null` returns from `SqlBreakdownBase.GetQuery<T>()` and its four overrides (LinqQueryBreakdown, SqlServer/PostgreSql/Snowflake QueryBreakdown) with `Enumerable.Empty<T>().AsQueryable()`, and tightens the signature from `IQueryable<T>?` to `IQueryable<T>`. The "we can't reconstruct" semantic now lives in "the query yields zero rows" rather than a nullable return, which is what callers in LINQ pipelines actually want. Three LinqQueryBreakdownTests tests asserting `Is.Null` are renamed and updated to assert `Is.Empty`. BREAKING CHANGE: SqlBreakdownBase.GetQuery<T> and the SqlServer / PostgreSql / Snowflake / LinqToSql QueryBreakdown.GetQuery<T> overrides no longer return `IQueryable<T>?`; they now return a non-nullable `IQueryable<T>` that is empty when reconstruction isn't possible. External NuGet consumers null- checking the result must switch to `.Any()` / `Is.Empty` checks instead. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
72072cec8e
commit
2c23ba4a88
@@ -272,17 +272,13 @@ public class QueryBreakdown : SqlServerQueryBreakdown
|
||||
/// Gets a LINQ to SQL query of the specified type based on this breakdown.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The entity type for the query.</typeparam>
|
||||
/// <returns>null by default, as QueryBreakdown operates on SQL. Override in derived classes to provide LINQ query reconstruction.</returns>
|
||||
/// <returns>An empty queryable by default, as QueryBreakdown operates on SQL. Override in derived classes to provide LINQ query reconstruction.</returns>
|
||||
/// <remarks>
|
||||
/// This PostgreSQL-specific implementation returns null since PostgreSQL QueryBreakdown represents parsed SQL statements.
|
||||
/// This PostgreSQL-specific implementation returns an empty queryable since PostgreSQL QueryBreakdown
|
||||
/// represents parsed SQL statements and has no built-in way to create LINQ queries.
|
||||
/// Derived classes can override this method to reconstruct LINQ queries from the analyzed components.
|
||||
/// </remarks>
|
||||
public override IQueryable<T>? GetQuery<T>() where T : class
|
||||
{
|
||||
// PostgreSQL breakdown represents parsed SQL statements and does not have a built-in way to create LINQ queries
|
||||
// Override in derived classes to provide LINQ query reconstruction if needed
|
||||
return null;
|
||||
}
|
||||
public override IQueryable<T> GetQuery<T>() where T : class => Enumerable.Empty<T>().AsQueryable();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user