簡體   English   中英

如何在EF代碼優先的數據類型為Medium Blob的表上聲明一個字段

[英]How do i declare a field on a table with the datatype of Medium Blob in EF Code First

我使用SnetientGuardian.EntityFrameworkCore.MySql使用dotnet Core EntityFramework

我有一個數據庫實體,其中一個名為ProfileImage的屬性存儲為下面的byte[] ... extract

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 DataType。

我的問題是如何將它設置為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");
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM