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: Relational: FirstOrDefault with projection and nav not being fully translated #5085

Closed
anpete opened this issue Apr 15, 2016 · 0 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Milestone

Comments

@anpete
Copy link
Contributor

anpete commented Apr 15, 2016

From MusicStore:

var cartItem 
    = _dbContext.CartItems
        .Select(ci => new CartItem 
            { 
                Count = ci.Count,
                Album = new Album { Title = ci.Album.Title }
            })
        .FirstOrDefault(
            ci => ci.CartId == _shoppingCartId
                && ci.CartItemId == id);

We get the following query plan:

dbug: Microsoft.EntityFrameworkCore.Query.Internal.SqlServerQueryCompilationContextFactory[5]
      TRACKED: False
      (QueryContext queryContext) => IEnumerable<CartItem> _ToSequence(
          element: CartItem FirstOrDefault(
              source: IEnumerable<CartItem> _Select(
                  source: IEnumerable<TransparentIdentifier<ValueBuffer, ValueBuffer>> _Where(
                      source: IEnumerable<TransparentIdentifier<ValueBuffer, ValueBuffer>> _ShapedQuery(
                          queryContext: queryContext,
                          shaperCommandContext: SelectExpression:
                              SELECT [ci].[Count], [ci.Album].[Title]
                              FROM [CartItems] AS [ci]
                              INNER JOIN [Albums] AS [ci.Album] ON [ci].[AlbumId] = [ci.Album].[AlbumId]
                          ,
                          shaper: CompositeShaper`3
                      )
                      ,
                      predicate: (TransparentIdentifier<ValueBuffer, ValueBuffer> t0) => new CartItem{
                          (int) object t0.Outer.get_Item(0)Count = Convert(t0.Outer.get_Item(0)),
                          new Album{ (string) object t0.Inner.get_Item(1)Title = Convert(t0.Inner.get_Item(1)) }
                          Album = new Album() {Title = Convert(t0.Inner.get_Item(1))}
                      }
                      .CartId == string GetParameterValue(
                          queryContext: queryContext,
                          parameterName: ___shoppingCartId_0
                      )
                       && new CartItem{
                          (int) object t0.Outer.get_Item(0)Count = Convert(t0.Outer.get_Item(0)),
                          new Album{ (string) object t0.Inner.get_Item(1)Title = Convert(t0.Inner.get_Item(1)) }
                          Album = new Album() {Title = Convert(t0.Inner.get_Item(1))}
                      }
                      .CartItemId == int GetParameterValue(
                          queryContext: queryContext,
                          parameterName: __id_1
                      )
                  )
                  ,
                  selector: (TransparentIdentifier<ValueBuffer, ValueBuffer> t0) => new CartItem{
                      (int) object t0.Outer.get_Item(0)Count = Convert(t0.Outer.get_Item(0)),
                      new Album{ (string) object t0.Inner.get_Item(1)Title = Convert(t0.Inner.get_Item(1)) }
                      Album = new Album() {Title = Convert(t0.Inner.get_Item(1))}
                  }
              )
          )
      )

This is because we would need to "lift" the FirstOrDefault predicate ahead of the projection (since it is expressed in terms of client objects).

Workaround is to move the predicate to a Where op ahead of the projection.

@rowanmiller rowanmiller added this to the Backlog milestone Apr 18, 2016
tuespetre added a commit to tuespetre/EntityFramework that referenced this issue Feb 4, 2017
tuespetre added a commit to tuespetre/EntityFramework that referenced this issue Feb 6, 2017
…ated

SQL

- Resolves dotnet#2341
- Resolves dotnet#5085
- Resolves dotnet#5230
- Resolves dotnet#6618
- Resolves dotnet#6647
- Resolves dotnet#6782
- Resolves dotnet#7080
- Resolves dotnet#7220
- Resolves dotnet#7417
- Resolves dotnet#7497
- Resolves dotnet#7523
- Resolves dotnet#7525
tuespetre added a commit to tuespetre/EntityFramework that referenced this issue Feb 6, 2017
…ated

SQL

- Resolves dotnet#2341
- Resolves dotnet#5085
- Resolves dotnet#5230
- Resolves dotnet#6618
- Resolves dotnet#6647
- Resolves dotnet#6782
- Resolves dotnet#7080
- Resolves dotnet#7220
- Resolves dotnet#7417
- Resolves dotnet#7497
- Resolves dotnet#7523
- Resolves dotnet#7525
tuespetre added a commit to tuespetre/EntityFramework that referenced this issue Feb 6, 2017
…ated

SQL

- Resolves dotnet#2341
- Resolves dotnet#5085
- Resolves dotnet#6618
- Resolves dotnet#6647
- Resolves dotnet#6782
- Resolves dotnet#7080
- Resolves dotnet#7220
- Resolves dotnet#7417
- Resolves dotnet#7497
- Resolves dotnet#7523
- Resolves dotnet#7525
tuespetre added a commit to tuespetre/EntityFramework that referenced this issue Feb 6, 2017
…ated

SQL

- Resolves dotnet#2341
- Resolves dotnet#5085
- Resolves dotnet#6618
- Resolves dotnet#6647
- Resolves dotnet#6782
- Resolves dotnet#7080
- Resolves dotnet#7220
- Resolves dotnet#7417
- Resolves dotnet#7497
- Resolves dotnet#7523
- Resolves dotnet#7525
tuespetre added a commit to tuespetre/EntityFramework that referenced this issue Feb 7, 2017
…ated

SQL

- Resolves dotnet#2341
- Resolves dotnet#5085
- Resolves dotnet#6618
- Resolves dotnet#6647
- Resolves dotnet#6782
- Resolves dotnet#7080
- Resolves dotnet#7220
- Resolves dotnet#7417
- Resolves dotnet#7497
- Resolves dotnet#7523
- Resolves dotnet#7525
tuespetre added a commit to tuespetre/EntityFramework that referenced this issue Feb 9, 2017
…ated

SQL

- Resolves dotnet#2341
- Resolves dotnet#5085
- Resolves dotnet#6618
- Resolves dotnet#6647
- Resolves dotnet#6782
- Resolves dotnet#7080
- Resolves dotnet#7220
- Resolves dotnet#7417
- Resolves dotnet#7497
- Resolves dotnet#7523
- Resolves dotnet#7525
@smitpatel smitpatel modified the milestones: Backlog, 3.0.0 Nov 13, 2019
@smitpatel smitpatel self-assigned this Nov 13, 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 Nov 13, 2019
smitpatel added a commit that referenced this issue Nov 13, 2019
smitpatel added a commit that referenced this issue Nov 21, 2019
smitpatel added a commit that referenced this issue Nov 22, 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-enhancement
Projects
None yet
Development

No branches or pull requests

3 participants