Description:
Migrating a system from .NET 4.8 to .NET 8 and EF Core 8.
When Entity Framework Core populates an entity from a table with a longblob column in it, the property populated from the longblob column in the database is an empty byte array even though there is data in the longlob column.
Appears to be similar to bug #108926 but with the latest versions of the Connector/NET
How to repeat:
Have a database table with a longlob column in it populated with data.
Use EF scaffolding to create a DBContext
Here is the model builder code we have generated:
modelBuilder.Entity<FileData>(entity =>
{
entity.HasKey(e => e.FileDataSha1Hash).HasName("PRIMARY");
entity.ToTable("file_data");
entity.Property(e => e.FileDataSha1Hash)
.HasMaxLength(40)
.IsFixedLength()
.HasColumnName("file_data_sha1_hash");
entity.Property(e => e.BinaryData)
.HasColumnName("binary_data")
.HasColumnType("longblob");
entity.Property(e => e.FileSize).HasColumnName("file_size");
});
Here is the corresponding FileData entity:
public partial class FileData
{
public string FileDataSha1Hash { get; set; }
public byte[] BinaryData { get; set; }
public int FileSize { get; set; }
}
The longblob column is binary_data and the entity property is byte[] BinaryData.
When the context is queried for a FileData entity that has binary data, the entity is returned with all properties populated correctly except for the BinaryData property, which is byte[0]. Note that the sample that was queried for had a longblob column with 101,033 bytes of data, so it is larger than blob, but smaller than mediumblob.
Sample Linq query that returns the entity:
FileData matchingFileData = context.FileData.Find(hash);