Path: redb/redb.Core/Query/Base/LazyReferencesQueryScope.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.Core/Query/Base/LazyReferencesQueryScope.cs
----
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using redb.Core.Data;
using redb.Core.Models.Configuration;
namespace redb.Core.Query.Base;
///
/// V4 (LAZY Л2): runs one query execution under a per-query WithLazyReferences override.
/// The override rides the same session flag the builders read ():
/// armed before the execution, restored to the global option after it. One implementation for the
/// flat and the tree providers, so the two cannot drift in how they arm, degrade and restore.
///
internal static class LazyReferencesQueryScope
{
public static async Task RunAsync(
IRedbContext context,
ISqlDialect sql,
RedbServiceConfiguration configuration,
ILogger? logger,
bool? lazyOverride,
Func> execute)
{
var toggled = false;
if (lazyOverride.HasValue && lazyOverride.Value != configuration.EnableLazyReferences)
{
// A provider without the channel (Pro SQLite has no session mechanism and may run
// without the native extension) degrades to the GLOBAL option - loudly, not silently.
try
{
await context.ExecuteScalarAsync