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

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

Open
thebestgin opened this issue Jun 9, 2021 · 14 comments
Assignees

Comments

@thebestgin
Copy link

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; }		
}
@JonathanMagnan JonathanMagnan self-assigned this Jun 10, 2021
@JonathanMagnan
Copy link
Member

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


Sponsorship
Help us improve this library

Performance Libraries
context.BulkInsert(list, options => options.BatchSize = 1000);
Entity Framework ExtensionsBulk OperationsDapper Plus

Runtime Evaluation
Eval.Execute("x + y", new {x = 1, y = 2}); // return 3
C# Eval FunctionSQL Eval Function

@thebestgin
Copy link
Author

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.

@JonathanMagnan
Copy link
Member

Hello @thebestgin

A simple reminder that we are here to assist you!

Don't hesitate to send your runnable project sample to our support team info@zzzprojects.com

Best regards,

Jon

@thebestgin
Copy link
Author

Hello Jon,

I have programmed an example project for you.

In the sample project everything works fine.

I first have to figure out what is different in my big project.

Thank you for your support.

@thebestgin
Copy link
Author

thebestgin commented Jun 19, 2021

Hello Jon,

I have reproduced the error.
EFPlusFutureProblemPostgres.zip

image

This is the reason of the error
image

With two futureValues the error occurs.
With one futureValue it works.

@JonathanMagnan
Copy link
Member

Thank a lot,

My developer will look at this.

@thebestgin
Copy link
Author

Do you have plans to make this feature available?

@JonathanMagnan
Copy link
Member

Unfortunately, we have currently way more requests than we can handle during the summer.

This request is currently in a pending state on our side.

Once we complete all the current requests, we will look at this list but for this moment, there is no short-term plan to make it happens. That's unfortunately impossible due to resource/time available ;(

@ipostanogov
Copy link

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)

@thebestgin
Copy link
Author

Hi @JonathanMagnan,

Your paid Entity Framework Extension Library has the same problem with the jsonb / json data type in FutureAction.
https://entityframework-extensions.net/bulk-merge#merge-with-future-action
The error occurs when there is more than one entity in a batch transaction.

We want to use Entity Framework Plus / Extension for our next products.
The missing feature with jsonb / json is really a pain point.
Entity Framework Plus / Extension with Postgres and jsonb would be such a booster.

I hope for a solution. Then we will invest in your paid Entity Framework Extension library.

Many thanks for your effort.

@JonathanMagnan
Copy link
Member

Hello @thebestgin ,

The FutureAction in EFE works very differently than FutureValue in EF Plus.

In fact, FutureAction just creates a pending list that will be executed later. So on this feature, there is nothing we can do or improve as the only thing this feature does is I will execute this same exact code but only when you call the Execute method.

FutureValue work differently as this is the one that batches multiple SQL Statement in the same command.

@colleonimattia
Copy link

I have the exact same problem.
Any updates on that?
Thanks,

M

@JonathanMagnan
Copy link
Member

Thank you for reaching out to ZZZ Projects, due to the holiday vacation we will have limited email access which may cause some delays from December 23 to January 2.
We are sorry for any inconvenience and will get back to you shortly.

@thebestgin
Copy link
Author

I have the exact same problem. Any updates on that? Thanks,

M

Unfortunately not.

There are only ugly workarounds.
Use a string data type instead of JSON. Use plain SQL or Dapper.

Maybe it is worth to open the issue in the Postgres community.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants