Hi!
Having the same issue as #432.
Can not insert value to a table with jsonb column (tried json also).
Insert code looks like this:
await _db.RequestLogs.InsertAsync(() =>
new RequestLog
{
RequestBody = JsonConvert.SerializeObject(requestBody),
});
pg logs:
2019-01-13 17:44:35.723 MSK [16200] ERROR: 42804: column "request_body" is of type jsonb but expression is of type text at character 129
2019-01-13 17:44:35.723 MSK [16200] STATEMENT: INSERT INTO clear_junction.request_log
(
request_body
)
VALUES
(
$1,
)
Interesting, that it is ok to insert with constant:
await _db.RequestLogs.InsertAsync(() =>
new RequestLog
{
RequestBody = "{""Body"": ""body value""}",
});
linq2db version: 2.6.1
Database Server: PostgreSQL 11.1
Database Provider: Npgsql 4.0.4
Operating system: Windows 10
Framework version: .NET Core 2.1
Which type has RequestBody?
RequestBody is a string (RequestLog is generated class)
What i suggest. Correct your T4 template and fix type for RequestBody it should be JToken.
Also you need this NpgSql plugin
https://www.npgsql.org/doc/types/jsonnet.html
Actually it should work with strings. Make sure your column attribute has DataType = DataType.BinaryJson property
Also if you use T4 to generate your mappings, set GenerateDataTypes=true; so DataType property will be generated for you
God bless you all!
GenerateDataTypes=true; was really missing...
Most helpful comment
Actually it should work with strings. Make sure your column attribute has
DataType = DataType.BinaryJsonproperty