Path: redb/redb.Core/Query/FieldPathRefusal.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/FieldPathRefusal.cs ---- using System; using System.Text.RegularExpressions; namespace redb.Core.Query; /// /// The one refusal of a field path a query cannot read: a filter, a sort, an aggregate, a group key or a window key /// whose path is not a chain of fields of the queried object, or that a provider cannot read. It is thrown before any /// statement runs, as , so the query never answers with another field's value. /// public static class FieldPathRefusal { /// The message of the refusal for the path (an expression or a field path). public static string Message(string path) => $"A query cannot read '{path}': the path must be a chain of fields of the queried object. " + "A filter, a sort and a window key take no method call inside the path (First(), ElementAt(...)); a sort and a " + "window key take no array or list element by index and no dictionary entry either. A filter of redb Pro reads " + "an element of an array or a list field of the object by a non-negative index, itself or one field of it " + "(Tags[0], Items[0].Name); the filters of redb.Postgres, redb.MSSql and redb.SQLite read none. The aggregates of " + "redb.Postgres, redb.MSSql and redb.SQLite read no field of an element of an array of classes by index " + "(Items[0].Price); redb Pro does. In a filter use Contains(...) for an array of simple values, Any(...) for an " + "array of list items, or a dictionary with its key; a value of your own goes on the other side of the comparison."; private static readonly Regex FieldOfElementByIndex = new(@"\[\d+\]\.", RegexOptions.Compiled | RegexOptions.CultureInvariant); /// /// For the providers whose aggregates are compiled by the SQL module in the database: refuses a field of an element /// of an array of classes by index (Items[0].Rank). The module reads no row for it and the aggregate came back as 0 /// or null. A field of a dictionary entry (ByKey[k].Rank) and an element of an array of simple values (Tags[0]) are /// read. An entry of a dictionary with an integer key whose value is a class (ById[5].Rank) cannot be told apart /// from an element by the path, and is refused as well. /// public static void EnsureModuleAggregateCanRead(string? fieldPath) { if (fieldPath != null && FieldOfElementByIndex.IsMatch(fieldPath)) throw new NotSupportedException(Message(fieldPath)); } }