Path: redb/redb.Tests.Integration/Tests/Base/LongBaseFilterTestsBase.cs Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Tests.Integration/Tests/Base/LongBaseFilterTestsBase.cs ---- using redb.Core; using redb.Core.Models.Contracts; using redb.Core.Models.Entities; using redb.Core.Query; using redb.Core.Query.Aggregation; using redb.Core.Query.Window; using redb.Tests.Integration.Models; namespace redb.Tests.Integration.Tests.Base; /// /// A filter on a base field whose SQL is long, here ParentId in some hundreds of ids, next to a filter on a field /// of the props. The answer is the children of the listed parents, on every provider. On SQL Server Free the base /// condition is moved out of the props filter as SQL text inside a JSON value and read back with JSON_VALUE, which gives /// NULL for a text over 4,000 characters: the condition vanished and the query returned every object the props filter /// let through. Short lists were right. /// public abstract class LongBaseFilterTestsBase { protected readonly IRedbService Redb; protected LongBaseFilterTestsBase(IRedbService redb) => Redb = redb; private const int Parents = 600; [Fact] public async Task ParentIdInHundredsOfIds_WithAPropsFilter_ReturnsOnlyTheirChildren() { await Redb.SyncSchemeAsync(); var tag = "lbf-" + Guid.NewGuid().ToString("N")[..8]; // Parents, and one more root whose children are not asked for. var roots = Enumerable.Range(0, Parents + 1) .Select(i => (IRedbObject)new RedbObject { name = $"{tag}-p{i}", Props = new NullComparisonProps { Tag = tag } }) .ToList(); var rootIds = await Redb.SaveAsync(roots); var listed = rootIds.Take(Parents).ToList(); var other = rootIds[^1]; // One child per listed parent, every third without a value for N; ten children of the other root. var children = listed.Select((pid, i) => (IRedbObject)new RedbObject { name = $"{tag}-c{i}", parent_id = pid, Props = new NullComparisonProps { Tag = tag, N = i % 3 == 0 ? null : i % 4 } }) .Concat(Enumerable.Range(0, 10).Select(i => (IRedbObject)new RedbObject { name = $"{tag}-o{i}", parent_id = other, Props = new NullComparisonProps { Tag = tag, N = 1 } })) .ToList(); await Redb.SaveAsync(children); var withValue = Enumerable.Range(0, Parents).Count(i => i % 3 != 0); IRedbQueryable Query() => Redb.Query() .WhereRedb(o => o.ParentId != null && listed.Contains(o.ParentId.Value)) .Where(p => p.Tag == tag); (await Query().CountAsync()).Should().Be(Parents, "the children of the listed parents, not every object of the tag"); (await Query().ToListAsync()).Should().HaveCount(Parents); (await Query().Where(p => p.N != null).CountAsync()).Should().Be(withValue); var groups = await Query().GroupBy(p => p.N).SelectAsync(g => new { g.Key, Count = Agg.Count(g) }); groups.Sum(g => g.Count).Should().Be(Parents, "the groups cover the listed parents' children only"); var sum = Enumerable.Range(0, Parents).Where(i => i % 3 != 0).Sum(i => i % 4); var agg = await Query().AggregateAsync(x => new { Total = Agg.Sum(x.Props.N), Count = Agg.Count() }); agg.Total.Should().Be(sum, "an aggregate over the listed parents' children"); agg.Count.Should().Be(Parents); var rows = await Query().WithWindow(w => w.OrderBy(p => p.N)).SelectAsync(x => new { x.Id, Row = Win.RowNumber() }); rows.Should().HaveCount(Parents, "a window over the listed parents' children"); var tree = await Redb.TreeQuery() .WhereRedb(o => o.ParentId != null && listed.Contains(o.ParentId.Value)) .Where(p => p.Tag == tag) .ToListAsync(); tree.Should().HaveCount(Parents, "a tree query over the listed parents' children"); } }