Skip to content

Load only what a projection reads from a collection - #1444

Merged
SimonCropp merged 1 commit into
mainfrom
projection-reads-collection-items
Oct 12, 2026
Merged

SimonCropp merged 1 commit into
mainfrom
projection-reads-collection-items

Conversation

@SimonCropp

Copy link
Copy Markdown
Owner

A projection that reads a collection through LINQ reads the item's properties off the lambda's own parameter:

GroupIds = _.AccessGroups.Select(_ => _.AccessGroupId).ToList()

ProjectionAnalyzer only followed member chains from the projection's parameter, so it recorded AccessGroups and nothing under it. A navigation with nothing recorded under it is loaded whole: every column of every item, with whatever the request selected under it loaded through an Include instead of a nested select.

The scalars the lambdas of the chain read from an item are now recorded under the collection, here AccessGroups.AccessGroupId, so only they are loaded.

Still loaded whole

When the lambdas need more than scalars of an item:

  • The items themselves come out, as from a Where with no Select after it, or FirstOrDefault.
  • A lambda reads a navigation of an item, or passes an item to a method.
  • There is no lambda, as in _.Items.Count().

Impact

No API change. A query for a field or filter with such a projection selects fewer columns, and returns the same data. In the app this came from, two snapshots changed, in SQL only.

Changes

  • ProjectionAnalyzer records the item properties.
  • Nine tests in ProjectionAnalyzerTests.
  • Version 36.1.0.

A projection that reads a collection through LINQ, such as

    GroupIds = _.AccessGroups.Select(_ => _.AccessGroupId).ToList()

reads AccessGroupId off the lambda's own parameter. ProjectionAnalyzer
only followed member chains from the projection's parameter, so it
recorded AccessGroups and nothing under it. A navigation with nothing
recorded under it is loaded whole: every column of every item, with
whatever the request selected under it loaded through an Include
instead of a nested select.

The scalars the lambdas of the chain read from an item are now recorded
under the collection, so only they are loaded.

The collection is still loaded whole when the lambdas need more than
scalars of an item: the items themselves come out, a navigation of an
item is read, an item is passed to a method, or there is no lambda.

Version 36.1.0.
@SimonCropp SimonCropp added this to the 36.1.0 milestone Oct 12, 2026
@SimonCropp
SimonCropp merged commit cdbd119 into main Oct 12, 2026
5 checks passed
@SimonCropp
SimonCropp deleted the projection-reads-collection-items branch October 12, 2026 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant