You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi!
I have a strange issue executing an update statement with a POCO that contains a JToken.
(ps: I n
Configuration:
I made a custom Mapper from DefaultMapper like the one described here: #326 to save/read JToken properties as JsonB in Postgresql.
I also add the 'NpgsqlConnection.GlobalTypeMapper.UseJsonNet();' configuration as described here: https://www.npgsql.org/doc/types/jsonnet.html
publicclassMyNpocoMapper:DefaultMapper{publicoverrideFunc<object,object>GetParameterConverter(DbCommanddbCommand,TypesourceType){if(sourceType==typeof(JToken)||sourceType==typeof(Newtonsoft.Json.Linq.JObject)||sourceType==typeof(Newtonsoft.Json.Linq.JArray)){return x =>newNpgsqlParameter{NpgsqlDbType=NpgsqlDbType.Jsonb,Value=x?.ToString()};}returnbase.GetParameterConverter(dbCommand,sourceType);}publicoverrideFunc<object,object>GetToDbConverter(TypedestType,MemberInfosourceMemberInfo){if(destType==typeof(JToken)||destType==typeof(Newtonsoft.Json.Linq.JObject)||destType==typeof(Newtonsoft.Json.Linq.JArray)){return x =>x;}returnbase.GetToDbConverter(destType,sourceMemberInfo);}publicoverrideFunc<object,object>GetFromDbConverter(TypedestType,TypesourceType){if(destType==typeof(JToken)||destType==typeof(Newtonsoft.Json.Linq.JObject)||destType==typeof(Newtonsoft.Json.Linq.JArray)){return x =>{if(xisstringserialized){returnJToken.Parse(serialized);}returnnull;};}returnbase.GetFromDbConverter(destType,sourceType);}}
When I try to update the same Poco I receive an exception: The CLR array type Newtonsoft.Json.Linq.JProperty isn't supported by Npgsql or your PostgreSQL.
Diggin in I discover that the issue reside into Sql class on Build method because the Database.UpdateStatements.PreparedUpdateStatement method make this (correct) query:
But after Sql.Build with ParameterHelper.ProcessParams transform it into: UPDATE "martianjson" SET "name" = @0, "data" = @1,@2,@3,@4, "createdby" = @5, "updatedby" = @6, "createdat" = @7, "updatedat" = @8 WHERE "id" = @9
as you can see "data" = @1 became "data" = @1,@2,@3,@4: seems that it 'explode' all the properties of the JToken in sub-parameters (of JsonProperty type..)
Someone can give me an help?
Thank you in advance!
The text was updated successfully, but these errors were encountered:
Hi!
I have a strange issue executing an update statement with a POCO that contains a JToken.
(ps: I n
Configuration:
I made a custom Mapper from DefaultMapper like the one described here: #326 to save/read JToken properties as JsonB in Postgresql.
I also add the 'NpgsqlConnection.GlobalTypeMapper.UseJsonNet();' configuration as described here: https://www.npgsql.org/doc/types/jsonnet.html
The poco classes and the example of insert
The insert/get statement works perfectly.
When I try to update the same Poco I receive an exception:
The CLR array type Newtonsoft.Json.Linq.JProperty isn't supported by Npgsql or your PostgreSQL.
Diggin in I discover that the issue reside into Sql class on Build method because the Database.UpdateStatements.PreparedUpdateStatement method make this (correct) query:
UPDATE "martianjson" SET "name" = @0, "data" = @1, "createdby" = @2, "updatedby" = @3, "createdat" = @4, "updatedat" = @5 WHERE "id" = @6
But after Sql.Build with ParameterHelper.ProcessParams transform it into:
UPDATE "martianjson" SET "name" = @0, "data" = @1,@2,@3,@4, "createdby" = @5, "updatedby" = @6, "createdat" = @7, "updatedat" = @8 WHERE "id" = @9
as you can see "data" = @1 became "data" = @1,@2,@3,@4: seems that it 'explode' all the properties of the JToken in sub-parameters (of JsonProperty type..)
Someone can give me an help?
Thank you in advance!
The text was updated successfully, but these errors were encountered: