Skip to content

Support arbitrary expressions in inline collections (translate to VALUES) #30734

@roji

Description

@roji

Our inline collection support currently supports constants:

public virtual Task Constant_Count_with_three_values(bool async)
    => AssertQuery(
        async,
        ss => ss.Set<PrimitiveCollectionsEntity>().Where(c => new[] { 2, 999, 1000 }.Count(i => i > c.Id) == 2),
        entryCount: 2);

While it's possible to also specify parameters, the NewArrayExpression gets client-evaluated by ParameterExtractingEV (because no database-correlated component), and so we get a single parameter for the array. This means we translate using OPENJSON, which isn't ideal - #30732 tracks doing a better translation to VALUES instead.

Beyond that, we could also allow arbitrary expressions:

var i = 2;

return AssertQuery(
    async,
    ss => ss.Set<PrimitiveCollectionsEntity>().Where(c => new[] { i, c.Int, SomeFunc(c.Foo) }.Contains(c.Id)),
    entryCount: 1);

The main blocker here is doing null semantics for InExpression over arbitrary expressions. Compensating to two-value logic isn't going to be easy...

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions