【问题标题】:How to store 'blob' type in MySQL with Entity Framework Core using byte[]?如何使用 byte[] 在 MySQL 中使用 Entity Framework Core 存储“blob”类型?
【发布时间】:2017-05-05 05:21:34
【问题描述】:

我的代码优先模型如下所示:

public class Document
{
    [Key]   
    public int DocumentId {get;set;}

    [Required]
    public byte[] Blob {get; set;}
}

我希望它映射到 MySQL 中的 blob 数据类型,但我不断收到 varbinary(255)

如何让它映射到“blob”?

【问题讨论】:

    标签: mysql entity-framework-core


    【解决方案1】:

    在你的 OnModelCreating 中做:

    modelBuilder.Entity<Document>(entity =>
    {
      entity.Property(x => x.Blob ).HasColumnType("blob");
    }
    

    【讨论】:

      【解决方案2】:

      我使用Pomelo.EntityFrameworkCore.MySql 来解决我的问题。

      【讨论】:

      • 如果 Pomelo 不是一个选项,解决方法是使用 text 类型来存储二进制数据。
      猜你喜欢
      • 1970-01-01
      • 2015-06-07
      • 1970-01-01
      • 1970-01-01
      • 2019-02-15
      • 1970-01-01
      • 2017-03-21
      • 1970-01-01
      • 2020-02-13
      相关资源
      最近更新 更多