Skip to content

Conversation

roji
Copy link
Member

@roji roji commented Aug 20, 2025

@AndriySvyryd, this is some WIP on switching from ClrCollectionAccessor to ClrIndexCollectionAccessor for complex JSON collections in the shaper, as discussed offline. See below for some possible issues - feel free to push changes to this PR from your side (or completely take over it if you want.

@roji roji requested a review from AndriySvyryd August 20, 2025 20:34
var result = (TResult)collectionAccessor!.Create();
// var collectionAccessor = relationship.GetCollectionAccessor();
#pragma warning disable EF1001 // Internal EF Core API usage.
var collectionAccessor = ((IRuntimePropertyBase)relationship).GetIndexedCollectionAccessor();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetIndexedCollectionAccessor() is only available on IRuntimePropertyBase (unlike GetCollectionAccessor() which is available on IPropertyBase). I don't have strong feelings here but maybe seems like they should be consistent?

Also note that GetIndexedCollectionAccessor is pubternal (another thing to maybe change).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is pubternal until we are satisfied with the API

@@ -1098,7 +1103,7 @@ static async Task<RelationalDataReader> InitializeReaderAsync(
{
manager.CaptureState();
var entity = innerShaper(queryContext, newKeyPropertyValues, jsonReaderData);
collectionAccessor.AddStandalone(result, entity);
// collectionAccessor.AddStandalone(result, entity);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea what this means (yet) but it doesn't exist on ClrIndexedCollectionAccessor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It allows to add an element to the collection without the containing object. We could add SetStandalone and CreateStandalone if necessary

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, Create should just be renamed to CreateStandalone as that would reflect the current behavior. Note that because the containing object could be a value type you would need to either use CreateStandalone with SetStandalone to populate the collection before materializing the containing object. Or use CreateStandalone and Set after materializing it.

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.

2 participants