Path: redb/redb.Tests.Integration/Tests/MsSqlPro/MsSqlProListRoundTripsTests.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/MsSqlPro/MsSqlProListRoundTripsTests.cs ---- using System.Data.Common; using System.Diagnostics; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using redb.Core.Extensions; using redb.Core.Pro.Extensions; using redb.MSSql.Pro.Extensions; using redb.Tests.Integration.Tests.Base; namespace redb.Tests.Integration.Tests.MsSqlPro; [Collection("MsSqlPro")] public class MsSqlProListRoundTripsTests : ListRoundTripsTestsBase { protected override void Register(IServiceCollection services, Action configure) => services.AddRedbPro(configure); protected override void UseProvider(RedbOptionsBuilder options) { var cs = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build().GetConnectionString("MSSql")!; options.UseMsSql(cs); } /// /// The list goes to the server as its builder writes it (the statement ToSqlStringAsync shows), with the scheme hash /// as a second result set of the same batch: no table variable around the page. The INSERT ... SELECT of the page into /// a table variable lost the parallel and the batch-mode plans of sorted and distinct pages. /// [Fact] public async Task ListStatement_IsSentAsBuilt_WithTheHashBesideIt() { var run = Guid.NewGuid().ToString("N")[..8]; var services = new ServiceCollection(); Register(services, options => { UseProvider(options); options.Configure(c => { c.EnablePropsCache = false; c.CacheDomain = $"round-trips-text-{run}"; }); }); await using var sp = services.BuildServiceProvider(); var redb = sp.GetRequiredService(); await redb.InitializeAsync(ensureCreated: true); await redb.SyncSchemeAsync(); var query = redb.Query().Where(p => p.Tag == run).OrderBy(p => p.Number).Take(10); await query.ToListAsync(); var preview = await query.ToSqlStringAsync(); var built = string.Join("\n", preview.Split('\n').Where(l => !l.TrimStart().StartsWith("--", StringComparison.Ordinal))).Trim(); var sent = new List(); using var observer = new ListenerObserver(listener => listener.Name != "SqlClientDiagnosticListener" ? null : listener.Subscribe(new EventObserver(e => { if (e.Key.EndsWith("WriteCommandBefore", StringComparison.Ordinal) && e.Value?.GetType().GetProperty("Command")?.GetValue(e.Value) is DbCommand command) lock (sent) sent.Add(command.CommandText); }))); using (DiagnosticListener.AllListeners.Subscribe(observer)) await query.ToListAsync(); lock (sent) { sent.Should().NotContain(s => s.Contains("@redb_page", StringComparison.Ordinal), "the page is not wrapped"); sent.Should().Contain(s => s.Contains(built, StringComparison.Ordinal) && s.Contains("_structure_hash FROM _schemes", StringComparison.Ordinal), "the list goes as its builder writes it, with the hash in its batch"); } } private sealed class ListenerObserver(Func onNext) : IObserver, IDisposable { private readonly List _subscriptions = []; public void OnNext(DiagnosticListener value) { if (onNext(value) is { } s) lock (_subscriptions) _subscriptions.Add(s); } public void OnError(Exception error) { } public void OnCompleted() { } public void Dispose() { lock (_subscriptions) foreach (var s in _subscriptions) s.Dispose(); } } private sealed class EventObserver(Action> onNext) : IObserver> { public void OnNext(KeyValuePair value) => onNext(value); public void OnError(Exception error) { } public void OnCompleted() { } } }