Hristo Kolev
Hristo Kolev

Reputation: 1574

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"?

Upvotes: 7

Views: 9200

Answers (2)

user2555515
user2555515

Reputation: 1029

In your OnModelCreating do:

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

Upvotes: 4

Hristo Kolev
Hristo Kolev

Reputation: 1574

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

Upvotes: 1

Related Questions