Skip to content

Normalization of array access to ElementAt breaks broke PG JSON array traversal #30386

@roji

Description

@roji

#29656 added CollectionIndexerToElementAtNormalizingExpressionVisitor to the preprocessing phase; this visitor normalizes array and list indexing (e.g. arr[2], list[2]) to ElementAt method calls.

Unfortunately, this breaks JSON array traversal on the PG side. The normalization itself isn't the issue,

Input query (test JsonPocoQueryTest.Array_of_object):

var x = ctx.JsonbEntities.Single(e => e.Customer.Orders[0].Price == 99.5m);

WIth 8.0-preview.1, we get the following tree after preprocessing:

DbSet<JsonbEntity>()
    .Where(j => j.Customer.Orders
        .Select(s => s.Price)
        .ElementAt(0) == 99.5)
    .Single()

Note how the member access for Price gets pulled up as a Select before the ElementAt; I'm guessing this is maybe the doing of nav expansion. In any case, this tree no longer faithfully represents what's going on; do we translate this construct in the EF SQL Server JSON support?

/cc @maumar

Metadata

Metadata

Assignees

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions