Topic
  • No replies
jackl206
jackl206
1 Post

Pinned topic System.InvalidCastException: Unable to cast object of type 'System.Int16' to type 'System.Nullable`1[System.Boolean]'.

‏2019-01-07T20:28:44Z | ibm.entityframeworkcore

Currently working with IBM.EntityFrameworkCore on .net 2.2 and getting Unable to cast object of type 'System.Int16' to type 'System.Nullable`1[System.Boolean]'.

It does not occur on the first call to the database. It only occurs on the second call to the database.

Database field is a boolean generated entity is also a Boolean.

Stack trace:  at lambda_method(Closure , MaterializationContext )
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.UnbufferedEntityShaper`1.Shape(QueryContext queryContext, ValueBuffer& valueBuffer)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Boolean& found)
   at lambda_method(Closure )
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ResultEnumerable`1.GetEnumerator()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider._TrackEntities[TOut,TIn](IEnumerable`1 results, QueryContext queryContext, IList`1 entityTrackingInfos, IList`1 entityAccessors)+MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Boolean& found)
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass15_1`1.<CompileQueryCore>b__0(QueryContext qc)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
   at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
   at Xyz.Infrastructure.Repository.XYZHandler.GetXYZ(Int32 conditionId) in C:\Xyz.Infrastructure\Repository\XYZRepository.cs:line 20
   at Xyz.Core.Application.Handler.XYZHandler.Handle(GetConditionQuery command) in C:\Xyz.Core\Application\Handler\XYZRepository.cs:line 22

 

Steps to reproduce

 public class TEST
    {
        public string ID { get; set; }
        public bool? TEST_BOOL { get; set; }
    }

Further technical details

EF Core version: (2.2.0)
Database Provider: (e.g. IBM.EntityFrameworkCore 1.3.0.100)
Operating system: Windows
IDE: (Visual Studio 2017 15.4)

 

We firstly raised the issue against EntityFramework Core at GitHub https://github.com/aspnet/EntityFrameworkCore/issues/14337. The feedback was "it is likely a IBMEntityframework core issue".

Updated on 2019-01-07T20:31:44Z at 2019-01-07T20:31:44Z by jackl206