Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store 'blob' type in MySQL with Entity Framework Core using byte[]?

I have code first model that looks like this:

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

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

I want that to map to blob data type in MySQL but I keep getting varbinary(255)

How do I get it to map to "blob"?

like image 817
Hristo Kolev Avatar asked Dec 20 '16 04:12

Hristo Kolev


2 Answers

I used Pomelo.EntityFrameworkCore.MySql to fix my problem.

like image 176
Hristo Kolev Avatar answered Nov 13 '22 15:11

Hristo Kolev


In your OnModelCreating do:

modelBuilder.Entity<Document>(entity =>
{
  entity.Property(x => x.Blob ).HasColumnType("blob");
}
like image 25
user2555515 Avatar answered Nov 13 '22 16:11

user2555515