Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query: collection.ToArray in projection #16318

Closed
smitpatel opened this issue Jun 27, 2019 · 2 comments
Closed

Query: collection.ToArray in projection #16318

smitpatel opened this issue Jun 27, 2019 · 2 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@smitpatel
Copy link
Contributor

        [ConditionalTheory]
        [MemberData(nameof(IsAsyncData))]
        public virtual Task Cast_ordered_subquery_to_base_type_using_typed_ToArray(bool isAsync)
        {
            return AssertQuery<City>(
                isAsync,
                cs => cs.Where(c => c.Name == "Ephyra").Select(
                    c => c.StationedGears.OrderByDescending(g => g.Nickname).Select(
                        g => new Officer
                        {
                            CityOrBirthName = g.CityOrBirthName,
                            FullName = g.FullName,
                            HasSoulPatch = g.HasSoulPatch,
                            LeaderNickname = g.LeaderNickname,
                            LeaderSquadId = g.LeaderSquadId,
                            Nickname = g.Nickname,
                            Rank = g.Rank,
                            SquadId = g.SquadId
                        }).ToArray<Gear>()),
                assertOrder: true,
                elementAsserter: CollectionAsserter<Gear>(e => e.Nickname, (e, a) => Assert.Equal(e.Nickname, a.Nickname)));
        }

How our collection materialization in relational goes over multiple rows is,
We create the result and inject empty list (or collection if coming from navigation) for parts.
Then we iterate over and populate those collections. Once that is done, we return the result.

ToArray call is problematic since we create a list but ToArray is called on list before we populate it. So we need to call ToArray after populating collection. But the way to find out collection is populated is when we reach row for next result. So we don't have data to compute non-collection part of result. We could potentially create Array directly and resize it as we add elements.
Work-around: do anonymous projection followed by AsEnumerable. Then it can be converted to whichever is desired shape.

@ajcvickers ajcvickers added this to the Backlog milestone Jun 28, 2019
@ajcvickers ajcvickers removed this from the Backlog milestone Jul 11, 2019
@ajcvickers
Copy link
Contributor

Marking for triage, since ASP.NET app is hitting this.

@DamianEdwards
Copy link
Member

@ajcvickers ajcvickers added this to the 3.0.0 milestone Jul 12, 2019
@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Aug 17, 2019
smitpatel added a commit that referenced this issue Aug 17, 2019
…ient code

The shapers on relational now take ResultContext which stores object[] of temporary values. Then populate the collection fully. Then call into client code to generate final result.

Resolves #16318
smitpatel added a commit that referenced this issue Aug 19, 2019
…ient code

The shapers on relational now take ResultContext which stores object[] of temporary values. Then populate the collection fully. Then call into client code to generate final result.

Resolves #16318
smitpatel added a commit that referenced this issue Aug 19, 2019
…ient code

The shapers on relational now take ResultContext which stores object[] of temporary values. Then populate the collection fully. Then call into client code to generate final result.

Resolves #16318
@ajcvickers ajcvickers modified the milestones: 3.0.0, 3.0.0-preview9 Aug 21, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0-preview9, 3.0.0 Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

3 participants