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:
Thom Lamb
2026-05-27 14:18:31 -05:00
co-authored by Claude Opus 4.7
parent 72072cec8e
commit 2c23ba4a88
6 changed files with 30 additions and 50 deletions
@@ -513,21 +513,21 @@ public class GetQueryTests
}
[Test]
public void GetQuery_LinqBreakdown_ReturnsNullByDefault()
public void GetQuery_LinqBreakdown_ReturnsEmptyByDefault()
{
// Arrange
var query = TestDataContext.Users.Where(u => u.Age > 18);
var breakdown = LinqQueryBreakdown.Analyze(query);
// Act - GetQuery returns null because LinqQueryBreakdown needs the original provider
// Act - GetQuery returns empty because LinqQueryBreakdown needs the original provider
var result = breakdown.GetQuery<User>();
// Assert
Assert.That(result, Is.Null);
Assert.That(result, Is.Empty);
}
[Test]
public void GetQuery_SqlServerQueryBreakdown_ReturnsNull()
public void GetQuery_SqlServerQueryBreakdown_ReturnsEmpty()
{
// Arrange
var breakdown = new QueryBreakdown("Id, Name", "Users", "Age > 18");
@@ -536,11 +536,11 @@ public class GetQueryTests
var result = breakdown.GetQuery<User>();
// Assert
Assert.That(result, Is.Null);
Assert.That(result, Is.Empty);
}
[Test]
public void GetQuery_MultipleBreakdownTypes_AllReturnNull()
public void GetQuery_MultipleBreakdownTypes_AllReturnEmpty()
{
// Arrange
var linqBreakdown = LinqQueryBreakdown.Analyze(TestDataContext.Users);
@@ -553,8 +553,8 @@ public class GetQueryTests
Assert.Multiple(() =>
{
// Assert
Assert.That(linqResult, Is.Null);
Assert.That(sqlResult, Is.Null);
Assert.That(linqResult, Is.Empty);
Assert.That(sqlResult, Is.Empty);
});
}