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: ProjectionShaper ignores the offset while Shaping #8095

Closed
smitpatel opened this issue Apr 6, 2017 · 5 comments
Closed

Query: ProjectionShaper ignores the offset while Shaping #8095

smitpatel opened this issue Apr 6, 2017 · 5 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

Query:

from c1_Orders in context.Orders
join _c1 in
   (from c1 in
	(from c in context.Customers
		orderby c.CustomerID
		select c)
	.Take(2)
	from c2 in context.Customers
	select new { CustomerID = EF.Property<string>(c1, "CustomerID") })
   .Distinct()
on EF.Property<string>(c1_Orders, "CustomerID") equals _c1.CustomerID
orderby _c1.CustomerID
select c1_Orders

Generates following query

exec sp_executesql N'SELECT [c1_Orders].[OrderID], [c1_Orders].[CustomerID], [c1_Orders].[EmployeeID], [c1_Orders].[OrderDate], [t0].[CustomerID]
FROM [Orders] AS [c1_Orders]
INNER JOIN (
    SELECT DISTINCT [t].[CustomerID]
    FROM (
        SELECT TOP(@__p_0) [c].*
        FROM [Customers] AS [c]
        ORDER BY [c].[CustomerID]
    ) AS [t]
    CROSS JOIN [Customers] AS [c2]
) AS [t0] ON [c1_Orders].[CustomerID] = [t0].[CustomerID]',N'@__p_0 int',@__p_0=2

Which is correct. Though it throws following exception.

Test 'Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests.QuerySqlServerTest.Lifting_when_subquery_nested_order_by_anonymous' failed:
	System.InvalidCastException : Unable to cast object of type 'System.Int32' to type 'System.String'.
	at lambda_method(Closure , QueryContext , TransparentIdentifier`2 )
	D:\EntityFramework\src\EFCore.Relational\Query\ExpressionVisitors\Internal\ProjectionShaper.cs(97,0): at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.ProjectionShaper.TypedProjectionShaper`3.Shape(QueryContext queryContext, ValueBuffer valueBuffer)
	D:\EntityFramework\src\EFCore.Relational\Query\ExpressionVisitors\Internal\CompositeShaper.cs(98,0): at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.CompositeShaper.TypedCompositeShaper`5.Shape(QueryContext queryContext, ValueBuffer valueBuffer)
	D:\EntityFramework\src\EFCore.Relational\Query\QueryMethodProvider.cs(48,0): at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_ShapedQuery>d__3`1.MoveNext()
	at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
	at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__1.MoveNext()
	at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
	D:\EntityFramework\src\EFCore\Query\Internal\LinqOperatorProvider.cs(178,0): at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__17`2.MoveNext()
	D:\EntityFramework\src\EFCore\Query\Internal\LinqOperatorProvider.cs(147,0): at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
	at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
	at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
	D:\EntityFramework\src\EFCore.Specification.Tests\QueryTestBase.cs(60,0): at Microsoft.EntityFrameworkCore.Specification.Tests.QueryTestBase`1.Lifting_when_subquery_nested_order_by_anonymous()
	D:\EntityFramework\test\EFCore.SqlServer.FunctionalTests\QuerySqlServerTest.cs(39,0): at Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests.QuerySqlServerTest.Lifting_when_subquery_nested_order_by_anonymous()

This exception happens because we do order by on client. The value comes from offset value buffer but projection shaper still tries to pick value from 0th index.

@ajcvickers ajcvickers added this to the 2.0.0 milestone Apr 7, 2017
@tuespetre
Copy link
Contributor

I can take this one if you want, @smitpatel

@smitpatel
Copy link
Contributor Author

@tuespetre - Sure. I haven't started work on this yet so you can go ahead with this. Thanks.

@anpete
Copy link
Contributor

anpete commented Apr 12, 2017

@tuespetre Any progress on this? 😁

@tuespetre
Copy link
Contributor

@anpete impeccable timing! Waiting on tests to finish running before pushing up the PR.

@anpete
Copy link
Contributor

anpete commented Apr 12, 2017

🎆 🍾

tuespetre added a commit to tuespetre/EntityFramework that referenced this issue Apr 12, 2017
@anpete anpete closed this as completed in dd548f3 Apr 12, 2017
@divega divega added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. labels May 8, 2017
@ajcvickers ajcvickers modified the milestones: 2.0.0-preview1, 2.0.0 Oct 15, 2022
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

5 participants