Repository navigation
Load only what a projection reads from a collection - #1444
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A projection that reads a collection through LINQ reads the item's properties off the lambda's own parameter:
ProjectionAnalyzeronly followed member chains from the projection's parameter, so it recordedAccessGroupsand 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 anIncludeinstead 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:
Wherewith noSelectafter it, orFirstOrDefault._.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
ProjectionAnalyzerrecords the item properties.ProjectionAnalyzerTests.