我正在使用 Dotnet Core EntityFramework 和 SapientGuardian.EntityFrameworkCore.MySql
我有一个数据库实体,它有一个名为 ProfileImage 的属性,存储为 byte[]
... 下面摘录
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; }
}
当它在 MySql 数据库中创建时,它会创建一个 BLOB 数据类型。
我的问题是如何将它设置为 MediumBlob?
编辑: 迁移(我忘了运行)产生了以下结果:
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);
}
}
最佳答案
您可以在 DbContext 中使用 Fluent API:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<ProfileEntity>().Property(p => p.ProfileImage)
.HasColumnType("MediumBlob");
}
关于c# - 我如何在 EF Code First 中声明数据类型为 Medium Blob 的表上的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46199370/