EntityFramework-Plus: Z.EntityFramework.Plus.EFCore: Postgres database, JSONB data type and FutureValue (InvalidCastException)

Hi,

I have a problem with Z.EntityFramework.Plus.EFCore in combination with Postgres database, JSONB data type and EFPlus FutureValue.

I got this exeption: System.InvalidCastException: 'Unable to cast object of type ‘System.String’ to type

Is there any change to fix the problem?

public class SomeClass
{
	publig int Id { get; set; }

    [Column(TypeName = "jsonb")]
    public SummeryPlain SummeryPlain { get; set; }		
}

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 1
  • Comments: 16 (6 by maintainers)

Most upvoted comments

Hi, @JonathanMagnan

Here is another example of an error related to postgres json mapping:

Unable to cast object of type 'System.String' to type 'System.Text.Json.JsonDocument'.
   at Z.EntityFramework.Plus.CreateEntityDataReader.GetFieldValue[T](Int32 ordinal)
   at lambda_method(Closure , QueryContext , DbDataReader , ResultContext , Int32[] , ResultCoordinator )
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
   at Z.EntityFramework.Plus.QueryFutureEnumerable`1.SetResult(IEnumerator`1 enumerator)
   at Z.EntityFramework.Plus.QueryFutureEnumerable`1.SetResult(DbDataReader reader)
   at Z.EntityFramework.Plus.QueryFutureBatch.ExecuteQueries()
   at Z.EntityFramework.Plus.QueryFutureEnumerable`1.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Z.EntityFramework.Plus.QueryIncludeFilterParentQueryable`1.CreateEnumerable()
   at Z.EntityFramework.Plus.QueryIncludeFilterParentQueryable`1.<GetAsyncEnumerator>b__25_1()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__274_0(Object obj)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location where exception was thrown ---
   at Z.EntityFramework.Plus.LazyAsyncEnumerator`1.FirstMoveNextAsync()
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at IncludeFilterDemo.Program.Main(String[] args) in ~/IncludeFilterDemo/Program.cs:line 42
   at IncludeFilterDemo.Program.Main(String[] args) in ~/IncludeFilterDemo/Program.cs:line 43
   at IncludeFilterDemo.Program.<Main>(String[] args)

Hello @thebestgin ,

Do you think you could provide a runnable project sample for this issue? It will help my developer to get started to investigate it faster and make sure nothing is missing.

Providing a project sample is now REQUIRED. It happened too many times that something was missing to investigate and/or answer an issue.

Try to create a new project with only the minimal code (having too many non-related codes doesn’t help either).

You can send it to info@zzzprojects.com if you need to keep the source private

Best Regards,

Jon

Sounds good. I will prepare an executable ASP Core Visual Studio project.