ExportXMLWordPrintableJSON

    • Type: Task
    • Resolution: Done
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Dotnet Drivers
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      Follow-up from the native scalar cardinality sub-project (SP4, epic EF-322).

      Current behavior (SP4): All(pred) goes native only when pred is a bare bool field (e.g. All(e => e.IsActive)). When pred is a comparison (e.g. All(e => e.Value > 0)), NativeCardinalityBinder.TryBindAggregate negates it via Expression.Not(pred.Body), producing a {{MongoUnaryExpression

      {Not}

      }} over a MongoBinaryExpression. MongoQueryLanguageRenderer.RenderUnary only supports Not over a bare bool MongoFieldExpression, so it throws NativeTranslationNotSupportedException. Net effect: All(comparison) falls back to driver-LINQ under MongoQueryMode.Native (correct results) and throws under NativeOnly. This is an accepted, non-breaking coverage gap — results are always correct.

      Proposed fix: negate the predicate at bind time by flipping the comparison operator (> → <=, >= → <, == → Unable to render embedded object: File (=}}, {{) not found.= → ==, < → >=, <= → >) and applying De Morgan over AndAlso/OrElse, instead of wrapping in Expression.Not. This yields a query-native negated predicate ($match ¬pred) so All(comparison) executes natively. Alternatively (or additionally), teach MongoQueryLanguageRenderer.RenderUnary to render Not over an arbitrary query-native comparison via $expr/$not — but the De Morgan flip is preferred (index-first, no $expr).

      Acceptance: All(e => e.Value > 0) and compound-predicate All go native (succeed under NativeOnly) with correct results, including the vacuous-true-over-empty case. The two existing tests in NativeCardinalityTests (All_over_empty_is_true, All_with_failing_element_is_false) should be updated from asserting fallback to asserting native execution.

      Referenced from the SP4 design/plan docs under docs/superpowers/.

            Assignee:
            Arthur Vickers
            Reporter:
            Arthur Vickers
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: