如何使用byte []在Entity Framework Core中存储'blob'类型?

问题描述 投票:5回答:2

我有代码第一个模型,看起来像这样:

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

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

我希望它映射到MySQL中的blob数据类型,但我一直得到varbinary(255)

如何让它映射到“blob”?

mysql entity-framework-core
2个回答
1
投票

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


0
投票

在你的OnModelCreating中:

modelBuilder.Entity<Document>(entity =>
{
  entity.Property(x => x.Blob ).HasColumnType("blob");
}
© www.soinside.com 2019 - 2024. All rights reserved.