EntityFramework-Plus
EntityFramework-Plus copied to clipboard
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; }
}
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 [email protected] 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 Extensions • Bulk Operations • Dapper Plus
Runtime Evaluation
Eval.Execute("x + y", new {x = 1, y = 2}); // return 3
C# Eval Function • SQL Eval Function
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 [email protected] if you need to keep the source private
Best Regards,
Jon
Sounds good. I will prepare an executable ASP Core Visual Studio project.
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 [email protected]
Best regards,
Jon
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.
Hello Jon,
I have reproduced the error. EFPlusFutureProblemPostgres.zip
This is the reason of the error
With two futureValues the error occurs. With one futureValue it works.
Thank a lot,
My developer will look at this.
Do you have plans to make this feature available?
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 ;(
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)
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.
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.
I have the exact same problem. Any updates on that? Thanks,
M
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.
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.