Im using dotnet Core EntityFramework using SapientGuardian.EntityFrameworkCore.MySql
I have a database Entity with a property called ProfileImage stored as a byte[]
... extract below
public class ProfileEntity
{
/// Gets or sets the full name.
/// </summary>
public string FullName { get; set; }
/// <summary>
/// A Byte Array with the profile image Bitmap
/// </summary>
public byte[] ProfileImage { get; set; }
}
When this get created in the MySql Database it creates a BLOB DataType.
My Question is how can set it to be a MediumBlob?
Edit: The Migration (which I forgot to run) produced the following:
public partial class AddMediumBlob : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<byte[]>(
name: "ProfileImage",
table: "ProfileEntity",
type: "MediumBlob",
nullable: true,
oldClrType: typeof(byte[]),
oldNullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<byte[]>(
name: "ProfileImage",
table: "ProfileEntity",
nullable: true,
oldClrType: typeof(byte[]),
oldType: "MediumBlob",
oldNullable: true);
}
}
You can use the Fluent API in your DbContext:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<ProfileEntity>().Property(p => p.ProfileImage)
.HasColumnType("MediumBlob");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With