.Net Core 6.0 , MySql Support LongBlob with Entity Framework is limited to small size
Posted by: volkhard vogeler
Date: October 26, 2022 02:11AM

Hello,

given is following .Net Core 6.0 C#-Program `

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Common;
using Microsoft.EntityFrameworkCore;
using MySql.Data.MySqlClient;
using MySql.EntityFrameworkCore.Extensions;

namespace ConsoleApp1
{
class Blob
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
[Column(TypeName = "LongBlob")]
public byte[] Data { get; set; }
}

class AppContext : DbContext
{
public DbSet<Blob> Blobs { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseMySQL("server=localhost;database=testblob;user=xyz;password=xyz");
}
}

internal class Program
{

static void Main(string[] args)
{
insert();
read();
}

private static void insert()
{
using (AppContext ctx = new AppContext())
{
ctx.Database.EnsureCreated();
int blobsize = 50;
byte[] bytes = null;
bytes = new byte[blobsize];
for (int i = 0; i < bytes.Length; i++)
{
bytes = Convert.ToByte(i % 256);
}

Blob one = new Blob {Data = bytes, Name = "Hello"};
ctx.Blobs.Add(one);
ctx.SaveChanges();
}
}

private static void read()
{
using (AppContext ctx = new AppContext())
{
foreach (Blob blob in ctx.Blobs)
{
Console.WriteLine($"{blob.Id}={blob.Data.Length}");
}
}
}
}
}
`

This Project is using the following packages:
- Microsoft.EntityFrameworkCore 6.0.10
- MySql.Data 8.0.31
- MySql.EntityFrameworkCore 6.0.7

This program inserts data to a table "Blobs" with some data inkl. a longblob column and reads in a second step that data and also writes the blob-size to the console

Starting this program is working fine. But when i set blobsize higher (e.g. 50000) then the blobsize is 0.

can anyone help?

best regards

Volkhard

Options: ReplyQuote


Subject
Written By
Posted
.Net Core 6.0 , MySql Support LongBlob with Entity Framework is limited to small size
October 26, 2022 02:11AM


Sorry, only registered users may post in this forum.

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.