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: runtime error when executing query projecting COALESCE(uint?, 0) #13753

Closed
maumar opened this issue Oct 25, 2018 · 1 comment
Closed
Assignees
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@maumar
Copy link
Contributor

maumar commented Oct 25, 2018

query using northwind model:

from o in ctx.Orders
select o.EmployeeID ?? 0;

query plan:

(QueryContext queryContext) => IEnumerable<uint> _InterceptExceptions(
|__ source: IEnumerable<uint> _ShapedQuery(
|   |__ queryContext: queryContext, 
|   |__ shaperCommandContext: SelectExpression: 
|   |       SELECT COALESCE([o].[EmployeeID], 0)
|   |       FROM [Orders] AS [o], 
|   |__ shaper: (QueryContext queryContext | ValueBuffer o) => (uint)Nullable<uint> TryReadValue(o, 0, null)), 
|__ contextType: TestModels.Northwind.NorthwindRelationalContext, 
|__ logger: DiagnosticsLogger<Query>, 
|__ queryContext: Unhandled parameter: queryContext)

exception:

An exception occurred while reading a database value. The expected type was 'System.UInt32' but the actual value was of type 'System.Int32'.
---- System.InvalidCastException : Specified cast is not valid.
	at Microsoft.EntityFrameworkCore.Storage.TypedRelationalValueBufferFactoryFactory.ThrowReadValueException[TValue](Exception exception, Object value, IPropertyBase property)
	at lambda_method(Closure , DbDataReader )
	at Microsoft.EntityFrameworkCore.Storage.Internal.TypedRelationalValueBufferFactory.Create(DbDataReader dataReader)
	at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer)
	at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
	at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
	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)
@maumar
Copy link
Contributor Author

maumar commented Oct 25, 2018

Another example of same/similar bug:

ctx.Customers.Select(c => c.Orders.OrderBy(o => o.OrderID).FirstOrDefault()).Select(e => e.EmployeeID)

query plan:

(QueryContext queryContext) => IEnumerable<Nullable<uint>> _InterceptExceptions(
|__ source: IEnumerable<Nullable<uint>> _ShapedQuery(
|   |__ queryContext: queryContext, 
|   |__ shaperCommandContext: SelectExpression: 
|   |       SELECT (
|   |           SELECT TOP(1) [o].[EmployeeID]
|   |           FROM [Orders] AS [o]
|   |           WHERE [c].[CustomerID] = [o].[CustomerID]
|   |           ORDER BY [o].[OrderID]
|   |       )
|   |       FROM [Customers] AS [c], 
|   |__ shaper: (QueryContext queryContext | ValueBuffer c) => (Nullable<uint>)Nullable<uint> TryReadValue(c, 0, null)), 
|__ contextType: TestModels.Northwind.NorthwindRelationalContext, 
|__ logger: DiagnosticsLogger<Query>, 
|__ queryContext: Unhandled parameter: queryContext)

exception:

The expected type was 'System.Nullable`1[System.UInt32]' but the actual value was of type 'System.Int32'.
---- System.InvalidCastException : Specified cast is not valid.
	at Microsoft.EntityFrameworkCore.Storage.TypedRelationalValueBufferFactoryFactory.ThrowReadValueException[TValue](Exception exception, Object value, IPropertyBase property)
	at lambda_method(Closure , DbDataReader )
	at Microsoft.EntityFrameworkCore.Storage.Internal.TypedRelationalValueBufferFactory.Create(DbDataReader dataReader)
	at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer)
	at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
	at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
	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)

@ajcvickers ajcvickers added this to the Backlog milestone Oct 26, 2018
@smitpatel smitpatel added add-regression-test closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed add-regression-test try-on-latest labels Dec 9, 2019
@smitpatel smitpatel modified the milestones: Backlog, 3.1.0 Dec 10, 2019
@smitpatel smitpatel self-assigned this Dec 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-query 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