Skip to content

Remove unneeded query root table when it's not needed in the query #33946

@roji

Description

@roji

For example, test Replace_ColumnExpression_in_column_setter:

await ss.Set<Owner>()
    .SelectMany(e => e.OwnedCollections)
    .ExecuteUpdateAsync(s => s.SetProperty(o => o.Value, "SomeValue"))

... produces the following SQL:

UPDATE [o0]
SET [o0].[Value] = N'SomeValue'
FROM [Owner] AS [o]
INNER JOIN [OwnedCollection] AS [o0] ON [o].[Id] = [o0].[OwnerId]

The SQL is overly-convoluted: it starts with the Owner table (since that's the query root in the LINQ query), although there's no need to reference that table at all in this query (this is because no OwnedCollections can ever exist without them having an Owner).

It's unclear at this point whether this is somehow specific to bulk updates, or a general query issue related to SelectMany(), etc.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions