EF is truncating JSON columns to 65k on insert statements
Posted by: Clodoaldo cltschoke
Date: February 28, 2018 11:32AM

Getting this error on inserting data into mysql table containing json column:

MySql.Data.MySqlClient.MySqlException (0x80004005): Invalid JSON text: "Missing a closing quotation mark in string." at position 65534 in value for column 'PropertyEvents.ContentObject'.

Based on the following log message, it appears that the INSERT statement generated by EF is limiting the parameter size to 65K, but couldnĀ“t understand why:

"Microsoft.EntityFrameworkCore.Database.Command:Error: Failed executing DbCommand (989ms) [Parameters=[@p0='?' (Size = 65535)], CommandType='Text', CommandTimeout='30']
INSERT INTO PropertyEvents (ContentObject) VALUES (@p0);
SELECT Id FROM PropertyEvents WHERE ROW_COUNT() = 1 AND Id=LAST_INSERT_ID();

This is the complete exception message:

MySql.Data.MySqlClient.MySqlException (0x80004005): Invalid JSON text: "Missing a closing quotation mark in string." at position 65534 in value for column 'PropertyEvents.ContentObject'.
at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.d__17.MoveNext()

Steps to reproduce
Configure EF Core Code First with the following entity type:
public class PropertyEvent
{
private PropertyEvent()
{
}

public int Id { get; private set; }
public string ContentObject { get; private set; }
}
using this configuration:
sealed class PropertyEventMap : IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder builder)
{
builder.Property(p => p.ContentObject).IsRequired().HasColumnType("JSON");
}
}

and then converts a json object greater than 65 k into PropertyEvent.ContentObject property and tries to insert it into db using "context.SaveChangesAsync()"

Further technical details
EF Core version: EF Core (2.01)
Database Provider: MySql.Data.EntityFrameworkCore (6.10.5) / MySQL 5.7.17
Operating system: Win10 Pro 64 bits (version 1709 build 16299.248)
IDE: Visual Studio 2017 (15.4.2)

Options: ReplyQuote


Subject
Written By
Posted
EF is truncating JSON columns to 65k on insert statements
February 28, 2018 11:32AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.